I have a problem with focus a ListView that contains an edittext. I use the method OnItemClickListener to select the row of the Listview, but when I click on the edit text it doesn't select the row.
I want that when I click on the edittext the row is selected thanks to the method OnItemClickListener, and after, the edittext takes focus to modify the text.
I'm losing very much time on this. Thanks.
this is the code.
list.xml
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="312dp"
android:descendantFocusability="beforeDescendants">
</ListView>
row.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/record"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
<TextView
android:id="@+id/itemOra"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Ora"
<TextView
android:id="@+id/itemPrezzo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.8"
android:focusable="false"
android:paddingBottom="3dip"
android:text="Prezzo"
android:textColor="#4d4d4d"
android:textSize="18dip"
/>
<EditText
android:id="@+id/itemMotivo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.8"
android:text="Motivo"
android:textColor="#4d4d4d"
android:textSize="18dip">
activity.java
..........
public void attachItemListener(){
searchResults.setOnItemClickListener(new OnItemClickListener() {
private Flusso corrente;
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
// TODO Auto-generated method stub
//NOW EDITTEXT CAN TAKE THE FOCUS.
Adapter.java
public class Adapter extends ArrayAdapter<Flusso> {
public List<Flusso> flussi;
public Adapter(Context context, int textViewResourceId,
List<Flusso> flussi) {
super(context, textViewResourceId, flussi);
this.flussi = flussi;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
return getView(position, convertView, parent, R.layout.row);
}
public View getView(int position, View convertView, ViewGroup parent, int layout) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)
this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(layout, null);
}
Flusso flow = flussi.get(position);
if (flow != null) {
TextView prezzo = (TextView) v.findViewById(R.id.itemPrezzo);
EditText motivo = (EditText) v.findViewById(R.id.itemMotivo);
TextView ora = (TextView) v.findViewById(R.id.itemOra);
prezzo.setText(Float.toString(flow.get_euro()));
motivo.setText(flow.get_perche());
}
return v;
}
}
This is the code. I don't know if there are problem with focus or other attributer. Itried with the method onTouchEvent but it doesn't work.
I need your help. Thanks