ниже мой код для списков может кто-нибудь сказать мне, как я могу получить событие для щелчка элемента?
public class MyCustomListView extends ListActivity
{
private ArrayList<String> m_orders=null;
private ArrayList<String> artistsList=new ArrayList<String>();
private OrderAdapter m_adapter;
String[] array;
String[] artists;
ListView listView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
Intent intent=getIntent();
array=intent.getStringArrayExtra("trackname");
artists=intent.getStringArrayExtra("artists");
m_orders = new ArrayList<String>();
for(int i=0;i<array.length;i++)
{
m_orders.add(array[i]);
artistsList.add(artists[i]);
}
this.m_adapter = new OrderAdapter(this, R.layout.row, m_orders);
setListAdapter(this.m_adapter);
}
private class OrderAdapter extends BaseAdapter
{
private ArrayList<String> items;
public OrderAdapter(Context context,int id,ArrayList<String> items)
{
super();
this.items=items;
}
public View getView(int position,View convertView,ViewGroup parent)
{
View view=convertView;
if(view==null)
{
LayoutInflater inflater=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view=inflater.inflate(R.layout.row,parent,false);
}
String string=items.get(position);
if(string!=null)
{
TextView t1=(TextView)view.findViewById(R.id.toptext);
TextView t2=(TextView)view.findViewById(R.id.bottomtext);
if(t1!=null)
{
t1.setText(items.get(position));
}
if(t2!=null)
{
String artistName=artistsList.get(position);
if(artistName.equals(""))
{
t2.setText("UnKnown");
}
else
{
t2.setText(artistName);
}
}
}
return view;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return array.length;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
}
@Override
public void onListItemClick(ListView arg0, View arg1, int arg2, long arg3) {
Log.i("Position",""+arg2);
}
что не так с этим кодом?