2012-02-03 5 views
1

J'ai une liste dans laquelle ils sont deux textview et un EditView dans une seule rangée. Je lie ces textviews et editview au moment de l'exécution et maintenant je veux faire une validation pour edittext dans listview, mais mon ID EditView est le même pour toutes les lignes, alors comment puis-je appliquer des validations dans cet editview plz m'aider.comment faire la validation dans Android EditText dans un ListView?

Merci à l'avance et désolé pour mon pauvre anglais

Mon code est ici

try { 
     json = new JSONObject(status); 
     getArray_Meter_Reading = new JSONArray(); 
     getArray_Meter_Reading = json.getJSONArray("meterReadings"); 

     myList = new ArrayList<HashMap<String, String>>(); 
     for (int i = 0; i < getArray_Meter_Reading.length(); i++) { 

      map = new HashMap<String, String>(); 

      String meter_Name = getArray_Meter_Reading.getJSONObject(i) 
        .getString("MeterName").toString(); 

      String previous_Meter_Reading = getArray_Meter_Reading 
        .getJSONObject(i).getString("PrevMeterReading") 
        .toString(); 

      map.put("meterName", meter_Name); 
      map.put("previousMeterReading", previous_Meter_Reading); 

      myList.add(map); 

     } 

    } catch (JSONException e) { 

     e.printStackTrace(); 
    } 

    SimpleAdapter myAdapter = new SimpleAdapter(this, myList, 
      R.layout.meter_reading_list, new String[] { 
        "meterName", "previousMeterReading" }, new int[] { R.id.txt_Meter_Name, 
        R.id.txt_Previous}); 

    lst.setAdapter(myAdapter); 

    lst.setOnTouchListener(new View.OnTouchListener() { 

     public boolean onTouch(View v, MotionEvent event) { 
      if(event.getAction() == MotionEvent.ACTION_MOVE){ 
       lst.scrollBy(0, 1); 
      } 
      return false; 
     } 
    }); 

et ma mise en page de Xml qui im ​​joli immeuble avec ce listview

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="horizontal" 
android:paddingBottom="6dip" 
android:paddingTop="4dip" > 

<TextView 
    android:id="@+id/txt_Meter_Name" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:width="140dp" /> 

<TextView 
    android:id="@+id/txt_Previous" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:width="100dp" /> 

<EditText 
    android:id="@+id/ed_Current" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:imeOptions="actionNext|actionDone" 
    android:singleLine="true" 
    android:width="100dp" > 
</EditText> 

+0

« mais mon ID EditView est identique pour toutes les lignes » ce n'est pas votre problème que seulement quelques EditViews existent, et non pour chaque ligne (uniquement pour ceux qui sont visibles) ... http: // www.youtube.com/watch?v=wDBM6wVEO70 – Selvin

Répondre

0
You have two way for this. 
1. Using Custom Adapter 
2.As you are doing..but when you are selecting position then you need to get view id like 

lst.setOnTouchListener(new View.OnTouchListener() { 

    public boolean onTouch(View v, MotionEvent event) { 
     if(event.getAction() == MotionEvent.ACTION_MOVE){ 
      lst.scrollBy(0, 1); 
     } 
     return false; 
    } 
}); 

You should take operation on View v.This view will give you differnt id as it have. 
I will suggest you to use custom adapter if not resolved this way as you are doing. 
+0

pouvez-vous me donner un exemple pour adaptateur custome afin que je puisse passer par là. –

+0

yes Veuillez patienter ... –

+0

list.setAdapter (new customadapter()); –

0

Construire un adaptateur personnalisé qui utilise votre HashMap et ...

Chaque fois que vous voulez faire du traitement avec les vues dans un ListView vous besoin de créer un adaptateur personnalisé qui va gérer votre logique mise en œuvre et transmettre cette information aux points de vue si nécessaire.

0
try this using custom adapter... 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
list = (ListView) findViewById(R.id.list); 

list.setAdapter(new customadapter()); 
} 

class customadapter extends BaseAdapter{ 

    public int getCount() { 
     // TODO Auto-generated method stub 
     return arraylist.size(); 
    } 

    public Object getItem(int position) { 
     // TODO Auto-generated method stub 
     return position; 
    } 

    public long getItemId(int position) { 
     // TODO Auto-generated method stub 
     return position; 
    } 

    public View getView(int postion, View convertView, ViewGroup parent) { 
     // TODO Auto-generated method stub 
     ViewHolder holder = null; 
     LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); 
     if (convertView == null) { 
      convertView = inflater.inflate(R.layout.readsggs_row, 
        null); 
      holder = new ViewHolder(); 
     }else 
     { 

       holder = (ViewHolder) convertView.getTag(); 

     } 
      //for (i = 0; i < DatabaseMethods.sggsbmid.size(); i++) { 
     convertView.setTag(holder); 
     if(postion%2==0) 
     { 
      convertView.setBackgroundColor(Color.parseColor("#A9BCF5")); 
     }else 
     { 
      convertView.setBackgroundColor(Color.parseColor("#ffffff")); 
     } 
     holder.textview = (TextView) convertView 
        .findViewById(R.id.text); 

     <///Like this text view you can use any view that you need////> 

     return convertView; 
    } 
    class ViewHolder { 
     TextView textview; 
    } 
} 
+0

Si vous avez un problème, dites-moi .... Son code de travail pour moi et je l'ai fait en tant que Tu es en train de faire. –

Questions connexes