/ / Клацніть список для ввімкнення текстового поля - android

Клацніть список, щоб увімкнути текстове поле - android

Я розробляю додаток для Android. Я хотів би дізнатися, як увімкнути прапорець, коли натискається елемент списку.

Це частина моєї основної діяльності, де парні пристрої з'являються у вигляді списку:

public void list(View view){
pairedDevices = BA.getBondedDevices();

ArrayList list = new ArrayList();
for(BluetoothDevice bt : pairedDevices)
list.add(bt.getName());

Toast.makeText(getApplicationContext(),"Showing Paired Devices",
Toast.LENGTH_SHORT).show();
final ArrayAdapter adapter = new ArrayAdapter
(this,android.R.layout.simple_list_item_1, list);
lv.setAdapter(adapter);


}

і це мій xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<ScrollView
android:id="@+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textAppearance="?android:attr/textAppearanceLarge" />

<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="on"
android:text="@string/on" />

<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="visible"
android:text="@string/Visible" />

<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="list"
android:text="@string/List" />

<Button
android:id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="off"
android:text="@string/off" />

<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible" >

</ListView>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Block Call"
android:id="@+id/chkBox"
android:layout_marginTop="139dp"
android:layout_alignTop="@+id/listView"
android:layout_centerHorizontal="true" />


</LinearLayout>
</ScrollView>

</RelativeLayout>

Відповіді:

0 для відповіді № 1

Ви маєте на увазі щось подібне

listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
CheckBox checkBox = (CheckBox) findViewById(R.id.checkbox_id);
checkBox.setChecked(true);
}
});

Це те, що ти хотів?


0 для відповіді № 2

ви можете включити або показати прапорець усередині setOnItemClickListener. щось на зразок цього:

 ListView listView = getListView();
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
// enable or show hidden checkbox here
}
});