1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| package com.example.test;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
public class TestAdapter extends BaseAdapter
{
String[] data;
boolean firstInit = true;
public TestAdapter(String[] array)
{
data = array;
}
public int getCount()
{
return data.length;
}
public Object getItem(int arg0)
{
return data[arg0];
}
public long getItemId(int arg0)
{
return arg0;
}
public View getView(int position, View arg1, ViewGroup arg2)
{
View view = arg1;
if (view == null)
{
LayoutInflater layoutInflater = (LayoutInflater) arg2.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate(R.layout.row, null);
}
((TextView)view.findViewById(R.id.rowText)).setText(data[position]);
if (firstInit && position == 0)
{
view.setSelected(true);
firstInit = false;
}
return view;
}
} |
Partager