-
-
Save kanytu/343adf3d246f49d683c9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import android.content.Context; | |
| import android.view.LayoutInflater; | |
| import android.view.View; | |
| import android.view.ViewGroup; | |
| import android.widget.ArrayAdapter; | |
| import android.widget.TextView; | |
| import android.widget.Toast; | |
| import java.util.List; | |
| /** | |
| * Created by poliveira on 23/02/2015. | |
| */ | |
| public class ExampleAdapter extends ArrayAdapter<String> { | |
| private List<String> mData; | |
| public ExampleAdapter(Context context, List<String> objects) { | |
| super(context, 0, objects); | |
| mData = objects; | |
| } | |
| @Override | |
| public View getView(final int position, View convertView, ViewGroup parent) { | |
| final ViewHolder holder; | |
| if (convertView == null) { | |
| convertView = LayoutInflater.from(getContext()).inflate(R.layout.simple_list_item_1, parent, false); | |
| holder = new ViewHolder(); | |
| holder.textView = (TextView) convertView; | |
| convertView.setTag(holder); | |
| holder.textView.setOnClickListener(new View.OnClickListener() { | |
| @Override | |
| public void onClick(View v) { | |
| Toast.makeText(getContext(), "Clicked in '" + mData.get(holder.position) + "'", Toast.LENGTH_SHORT).show(); | |
| } | |
| }); | |
| } else { | |
| holder = (ViewHolder) convertView.getTag(); | |
| } | |
| holder.textView.setText(mData.get(position)); | |
| holder.position = position; | |
| return convertView; | |
| } | |
| static class ViewHolder { | |
| public TextView textView; | |
| public int position; | |
| } | |
| } |
thanks
Thanks man.
LayoutInflater.from(getContext()).inflate(R.layout.simple_list_item_1, parent, false);That line nailed it
Thanks, man!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you