android-listview - 在android中,如何设置事件 onclick listview ( 多个 listview )

  显示原文与译文双语对照的内容
0 0

我是安卓初学者。我有 3个标签控制( 每个选项卡控件都有列表视图) 。 类活动我有函数:


 @Override

 protected void onListItemClick(ListView l, View v, int position, long id) {
//TODO Auto-generated method stub
 super.onListItemClick(l, v, position, id);
 TextView link=(TextView)findViewById(R.id.txt1);
 link.setText("Hot news>> "+lv_arr[position]);
 LinearLayout llo=(LinearLayout)findViewById(R.id.lout_link);
 Button bt_link=new Button(this);
 bt_link.setText("test");
 llo.addView(bt_link);
 }

它只使用 listview ( 。第一个 tabcontrol,它不工作的其他tabcontrol中的listview ) 。 那么如何在第二个tabcotrol中设置事件 onclick listview? 非常感谢你。

时间: 原作者:

0 0

你可以为三个列表设置 3个不同的onClickListeners

请使用以下命令:


list1.setOnclickListener(list1ClickListener);
list2.setOnclickListener(list2ClickListener);
list3.setOnclickListener(list3ClickListener);


还有 listItemClickLiteners:


/*Item click listener for the list1 item click event.*/
 final private transient OnItemClickListener list1ClickListener = new OnItemClickListener() {

/*(non-Javadoc)
 * @see
 * android.widget.AdapterView.OnItemClickListener#onItemClick(android
 *. widget.AdapterView, android.view.View, int, long) */

 @Override
 public void onItemClick(final AdapterView<?> parent, final View view,
 final int position, final long itemID) {
 }

/*Item click listener for the list2 item click event.*/
 final private transient OnItemClickListener list2ClickListener = new OnItemClickListener() {

 @Override
 public void onItemClick(final AdapterView<?> parent, final View view,
 final int position, final long itemID) {
 }

/*Item click listener for the list3 item click event.*/
 final private transient OnItemClickListener list3ClickListener = new OnItemClickListener() {

 @Override
 public void onItemClick(final AdapterView<?> parent, final View view,
 final int position, final long itemID) {
 }

原作者:
0 0

Shirikants答案工作( 只需添加几个大括号)


/* Item click listener for the list1 item click event. */
private transient OnItemClickListener list1ClickListener = new OnItemClickListener() {

/*
 * (non-Javadoc)
 * 
 * @see
 * android.widget.AdapterView.OnItemClickListener#onItemClick(android
 *. widget.AdapterView, android.view.View, int, long)
 */

 @Override
 public void onItemClick(final AdapterView<?> parent, final View view,
 final int position, final long itemID) {
 }
};

/* Item click listener for the list2 item click event. */
private transient OnItemClickListener list2ClickListener = new OnItemClickListener() {

 @Override
 public void onItemClick(final AdapterView<?> parent, final View view,
 final int position, final long itemID) {
 }
};

/* Item click listener for the list3 item click event. */
private transient OnItemClickListener list3ClickListener = new OnItemClickListener() {

 @Override
 public void onItemClick(final AdapterView<?> parent, final View view,
 final int position, final long itemID) {
 }
};

原作者:
...