我使用JSON從Web服務器獲取數據項Title和Description。我知道如何解析它,使用一個自定義適配器,並使用僅標題填充列表視圖。我希望它打開一個新的活動並顯示所點擊的項目的標題和描述。我是否必須創建一個新的自定義適配器來填充此列表視圖?我應該從活動的這一邊通過什麼,如何從另一邊接受?提前致謝。當在Listview上點擊標題項時獲取標題和描述android
displayTitleAdapter = new DisplayTitleAdapter(this, R.layout.rowlayout);
listView = (ListView)findViewById(R.id.listviewfinal);
listView.setAdapter(displayTitleAdapter);
listView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
這是我的適配器類的getView方法
public View getView(int position, View convertView, ViewGroup parent) {
View row;
row = convertView;
ReqHolder reqHolder;
if(row == null){
LayoutInflater layoutInflate = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = layoutInflate.inflate(R.layout.rowlayout, parent, false);
reqHolder = new ReqHolder();
reqHolder.Title = (TextView)row.findViewById(R.id.title_title);
reqHolder.Requirement = (TextView)row.findViewById(R.id.req_req);
row.setTag(reqHolder);
}
else{
reqHolder = (ReqHolder)row.getTag();
}
//Requirements is the model class with getter and setter methods for Fields Title and Requirement.
Requirements requirements = (Requirements) this.getItem(position);
reqHolder.Title.setText(requirements.getTitle());
reqHolder.Requirement.setText(requirements.getRequirement());
return row;
}
static class ReqHolder{
TextView Title;
TextView Requirement;
}
}
我用這種方法發送序列化類和@ dh19的方法來接收它,它工作!謝謝。 – Wagari
不客氣 – Mohamed