|
|
|
Android อยากทราบวิธีเพิ่ม button บน listview ที่รับข้อมูมาจาก mysql ครับ |
|
|
|
|
|
|
|
บทความนี้เลยครับ
Android ListView and Buttons inside Create Custom Command in ListView
|
|
|
|
|
Date :
2015-03-16 10:44:26 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (Android-Java)
public void SearchData()
{
// listView1
ListView listView1 = (ListView)findViewById(R.id.listView4);
// editText1
final EditText inputText = (EditText)findViewById(R.id.txtid3);
Intent intent = getIntent();
final String Subject = intent.getStringExtra("Subjectname");
final String Teacher = intent.getStringExtra("Username");
final int num =1;
String url = "http://jojoproject.orgfree.com/android/getListQuestion.php";
// Paste Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("txtKeyword", inputText.getText().toString()));
params.add(new BasicNameValuePair("txtSubject", Subject));
params.add(new BasicNameValuePair("txtTeacher", Teacher));
try {
JSONArray data = new JSONArray(getJSONUrl(url,params));
ArrayList<HashMap<String, String>> MyArrList = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map;
for(int i = 0; i < data.length(); i++){
JSONObject c = data.getJSONObject(i);
map = new HashMap<String, String>();
map.put("testname", c.getString("testname"));
MyArrList.add(map);
}
listView1.setAdapter(new ImageAdapter(this));
//SimpleAdapter sAdap;
//sAdap = new SimpleAdapter(Teacher_question_list.this, MyArrList, R.layout.activity_column2,
//new String[] {"testname"}, new int[] {R.id.ColName2});
//lisView1.setAdapter(sAdap);
//lisView1.setOnItemClickListener(new OnItemClickListener(){
//public void onItemClick(AdapterView<?> parent, View view,
//int position, long id){
//String strTestname = MyArrList.get(position).get("testname")
//.toString();
//}
//});
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public class ImageAdapter extends BaseAdapter
{
private Context context;
public ImageAdapter(Context c)
{
// TODO Auto-generated method stub
context = c;
}
public int getCount() {
// TODO Auto-generated method stub
return MyArrList.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(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = inflater.inflate(R.layout.activity_column2, null);
}
return convertView;
}
}
มันติดที่ MyArrList ใน class ImageAdapter อะครับ "MyArrList cannot be resolved"
|
ประวัติการแก้ไข 2015-03-24 13:07:21
|
|
|
|
Date :
2015-03-19 22:03:10 |
By :
maxdarline |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ไว้บนสุดในส่วนไหนครับ ถ้าในฟังชั่น SearchData มีแล้วนะครับ หรือต้องไว้นสุดของฟังชั่นเลย แต่ลองทำแล้วก็ยังเออเร่ออะครับ
|
|
|
|
|
Date :
2015-03-20 10:15:27 |
By :
maxdarline |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|