开发者

android ListView ItemClick get the Child Text

I have made a custom listView which which extends ListActivity and each row contains 2 textview and a button.

adapter = new SimpleAdapter(this, arraylist, R.layout.simplelistcustom, new String[] { "count","title"}, 
                new int[] {R.id.invisible, R.id.textView11 });
        setListAdapter(adapter);

When clicking on the List View row ,i get the selected row index and by using the index i get the row child

protected void onListItemClick(ListView listView, View view, int position, long id)
    {
         super.onListItemClick(listView, view, position, id);
         String selection = listView.getItemAtPosition(position).toString(); 
  }

The output when i displayed in the "selection" in Logcat is

{count=6, title=etywewetr}

Problem is i want to seperate the conten开发者_如何学JAVAt....How can this possible....plz help

thanx in advance


The getItemAtPosition method is returning you an element from your arraylist parameter; you just need to cast it to the correct type. Assuming your arraylist is a List<Map<String, String>> (which I suspect it is):

protected void onListItemClick(ListView listView, View view, int position, long id)
{
     super.onListItemClick(listView, view, position, id);
     Map<String, String> selection = (Map<String, String>) listView.getItemAtPosition(position);
     String count = selection.get("count");
     String title = selection.get("title");
}


 static class MyViewHolder extends ViewHolder {   

        public MyViewHolder(TextView  t2,TextView t1) {          

            text1 = t1;
            text2 = t2;   
        }   
        TextView text1;
        TextView text2;   
    }   
private class MyClickableListAdapter extends ClickableListAdapter {   
        public MyClickableListAdapter(Context context, int viewid,   
                List<MyData> objects) {   
            super(context, viewid, objects);   
            // nothing to do   
        }   

        protected void bindHolder(ViewHolder h) {   

            MyViewHolder mvh = (MyViewHolder) h;   
            MyData mo = (MyData)mvh.data;    
            mvh.text.setText(mo.text);   
            mvh.text1.setText(mo.text1);
        }   
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜