Veri formu sql veritabanını getiriliyor ve ben MyCustomAdapter sınıfa verileri geçirerek zaman ArrayList (bir sınıftır hangisi) Öğrenci yazmak için String değişmesi gerekiyor, Şimdi JSONListView.
try {
JSONObject jsonObj = new JSONObject(myJSON);
peoples = jsonObj.getJSONArray("result");
ArrayList<String> personList=null;
for (int i = 0; i < peoples.length(); i++) {
JSONObject c = peoples.getJSONObject(i);
String roll = c.getString(TAG_ROLL);
personList = new ArrayList<String>();
personList.add(i, roll);
}
dataAdapter = new MyCustomAdapter(this, R.layout.list_item, persons);
ListView listView = (ListView) findViewById(R.id.listView);
listView.setAdapter(dataAdapter);
kullanarak almak am
MyCustomAdapter.java
public class MyCustomAdapter extends ArrayAdapter {
public ArrayList<Student> personList;
public MyCustomAdapter(Context context, int resource, ArrayList<Student> personList) {
super(context, resource, personList);
this.personList=new ArrayList<Student>();
this.personList.addAll(personList);
}
private class ViewHolder{
TextView roll;
TextView name;
CheckBox check;
}
public View getView(int position, View convertView, ViewGroup parent){
ViewHolder holder=null;
Log.v("ConvertView", String.valueOf(position));
if(convertView==null){
LayoutInflater vi = (LayoutInflater)getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
convertView = vi.inflate(R.layout.list_item, null);
holder=new ViewHolder();
holder.roll=(TextView)convertView.findViewById(R.id.roll);
holder.name=(TextView)convertView.findViewById(R.id.name);
holder.check=(CheckBox)convertView.findViewById(R.id.checkBox);
convertView.setTag(holder);
holder.name.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CheckBox cb=(CheckBox) v;
Student student=(Student)cb.getTag();
Toast.makeText(getContext(), "Clicked on Checkbox: " + cb.getText() +
" is " + cb.isChecked(), Toast.LENGTH_SHORT).show();
student.setSelected(cb.isChecked());
}
});
}
else{
holder=(ViewHolder)convertView.getTag();
}
Student student=personList.get(position);
holder.roll.setText(" (" + student.getRollno() + ")");
holder.name.setText(student.getName());
holder.check.setChecked(student.isSelected());
holder.check.setTag(student);
return convertView;
}
}
Student.java
public class Student {
String rollno;
String name;
Boolean selected;
public Student(String rollno, String name, Boolean selected){
super();
this.rollno=rollno;
this.name=name;
this.selected=selected;
}
public String getRollno(){
return rollno;
}
public void setRollno(String rollno){
this.rollno=rollno;
}
public String getName(){
return name;
}
public void setName(String name){
this.name=name;
}
public Boolean isSelected(){
return selected;
}
public void setSelected(boolean selected) {
this.selected = selected;
}
}
Verileri özel adaptörüme nasıl aktarmalıyım?
Çok teşekkür ederim! Çok uzun bir süre boyunca sıkışmıştı.+1 – GMehta
hoşgeldiniz ... –