嗨,我需要有关 listview 行中活动按钮的帮助。想法是然后我按下它更改文本视图的行中的按钮。此列表行必须在setOnItemLongClickListener () 中激活;谁能告诉我示例或教程如何制作这样的东西或一些示例或显示我的问题?我厌倦了谷歌它并且不会得到答案......我是android新手,很抱歉我的语言和tnx有任何帮助;)我的想法。
+-----------------------------------------+
| textview | textview | textview | Button |
+----------+----------+----------+--------+
| textview | textview | textview | Button |
+-----------------------------------------+
然后按钮按下 textview 变成这样的数字:
+-----------------------------------------+
| textview | textview | textview | Button |
+----------+----------+----------+--------+
| textview | textview | 1 | Button | <- this button was pressed
+-----------------------------------------+
我做了然后按钮改变它,但问题是它改变了更多的行。像
+-----------------------------------------+
| textview | textview | textview | Button |
+----------+----------+----------+--------+
| textview | textview | 1 | Button | <- this button was pressed
+-----------------------------------------+
| textview | textview | textview | Button |
+----------+----------+----------+--------+
| textview | textview | 1 | Button | <- this button was **not** pressed
+----------+----------+----------+--------+
| textview | textview | textview | Button |
+----------+----------+----------+--------+
| textview | textview | 1 | Button | <- this button was **not** pressed
+-----------------------------------------+
我正在使用 SimpleAdapter 来获取列表。
ListView lv = getListView();
lv.setOnItemLongClickListener(listener);
OnItemLongClickListener listener = new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> parent, final View view, int position, long id) {
btn1 = (Button) view.findViewById(R.id.button1);
btn1.setOnClickListener(new OnClickListener(){
int number= 0;
public void onClick(View v) {
// TODO Auto-generated method stub
TextView textView = (TextView) v.findViewById(R.id.textView_must_be_changed);
number++;
textView.setText(String.valueOf(number));
}
});
}
};
我的布局 XML 是
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:id="@+id/gridas"
android:layout_height="fill_parent"
android:choiceMode="multipleChoice"
android:columnCount="10"
android:descendantFocusability="beforeDescendants" >
<TextView
android:id="@+id/Textview"
android:layout_column="5"
android:layout_columnSpan="3"
android:layout_gravity="left|bottom"
android:layout_row="1"
android:layout_rowSpan="2"
android:text="4.3 kg" />
<TextView
android:id="@+id/Textview"
android:layout_column="7"
android:layout_gravity="left"
android:layout_row="1"
android:layout_rowSpan="2"
android:text="35 cm" />
<TextView
android:id="@+id/Textview"
android:layout_width="163dp"
android:layout_height="49dp"
android:layout_column="9"
android:layout_gravity="left"
android:layout_row="2"
android:gravity="left"
android:text="949.00 Lt"
android:textSize="32sp"
android:textStyle="bold" />
<TextView
android:id="@+id/**textView_must_be_changed**"
android:layout_column="9"
android:layout_gravity="left|top"
android:layout_row="1"
android:text="tekstukas"
/>
<Button
android:id="@+id/button1"
android:layout_column="9"
android:layout_gravity="left|top"
android:layout_row="3"
android:text="Button"
android:focusable="false"
android:focusableInTouchMode="false"/>
</GridLayout>