Edittext And Buttons In Listview Android
I have created custom ListView which is having two TextViews, Two Buttons and one EditText, My problem is: 1) Edit text is loosing control even after adding android:descendantFocus
Solution 1:
I suggest try to implement custom listview for this we create a adapter in which we will create two layouts
Layout1)
<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent" ><ListViewandroid:id="@+id/listView1"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:layout_alignParentTop="true" ></ListView></RelativeLayout>
Layout2)
<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent" ><TextViewandroid:id="@+id/textView1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:layout_alignParentTop="true"android:text="TextView" /><TextViewandroid:id="@+id/textView2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:layout_below="@+id/textView1"android:layout_marginTop="16dp"android:text="TextView" /><EditTextandroid:id="@+id/editText1"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_alignBottom="@+id/textView2"android:layout_marginLeft="20dp"android:layout_marginRight="20dp"android:layout_toRightOf="@+id/textView1"android:ems="10" ><requestFocus /></EditText><Buttonandroid:id="@+id/button2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignBaseline="@+id/button1"android:layout_alignBottom="@+id/button1"android:layout_alignParentRight="true"android:text="Button" /><Buttonandroid:id="@+id/button1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:layout_below="@+id/textView2"android:layout_marginTop="29dp"android:text="Button" /></RelativeLayout>
And in .java class create a custom adapter for listview Test.java)
publicclassTesttttextendsActivity {
ListView listView;
CustomAdapter adapter;
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.direction);
findId();
executionMethod();
}
privatevoidfindId() {
listView = (ListView) findViewById(R.id.listView1);
adapter = newCustomAdapter(this);
}
privatevoidexecutionMethod() {
listView.setAdapter(adapter);
}
classCustomAdapterextendsBaseAdapter {
publicCustomAdapter(Context convertView) {
}
@OverridepublicintgetCount() {
return0;
}
@Overridepublic Object getItem(int position) {
returnnull;
}
@OverridepubliclonggetItemId(int position) {
// TODO Auto-generated method stubreturn0;
}
@Overridepublic View getView(int position, View convertView, ViewGroup parent) {
LayoutInflaterinflater= LayoutInflater
.from(getApplicationContext());
Viewview= inflater.inflate(R.layout.qwerty, null);
Buttonbtn1= (Button) view.findViewById(R.id.button1);
Buttonbtn2= (Button) view.findViewById(R.id.button2);
EditTextedt= (EditText) view.findViewById(R.id.editText1);
return view;
}
}
}
It should be note that in customadapter class you can set functionality in particular item according to your requirement
Solution 2:
In your manifest file add android:windowSoftInputMode="stateHidden|adjustPan"
under activity tag in which you have made list view
Post a Comment for "Edittext And Buttons In Listview Android"