我是android初学者。我有3个选项卡控件(每个选项卡控件都有列表视图)。 class Active我有函数:
@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,listview在其他tabcontrol中不起作用)。
那么如何在第二个,第三个tabcotrol中设置事件onclick
listview? 。
非常感谢。
答案 0 :(得分:1)
您可以为三个列表设置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) {
}
答案 1 :(得分: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) {
}
};