我正在使用地图将值传递给自定义适配器。如何获取自定义适配器中的值。我的应用程序显示空白屏幕,没有任何错误。
文件
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class archive extends Fragment {
public archive() {
}
private archiveadapter tableRowAdapter;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.v("ListFragment", "onCreate()");
}
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Log.v("ListFragment", "onActivityCreated().");
Log.v("ListsavedInstanceState", savedInstanceState == null ? "true"
: "false");
// Generate list View from ArrayList
displayListView();
}
public static final String ARG_SECTION_NUMBER = "section_number";
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater
.inflate(R.layout.moderationrequests, container, false);
return v;
}
private void displayListView() {
List<String> dialogtitle = new ArrayList<String>();
dialogtitle
.add("Thief nabbed selling stolen mower to owner: Stupid, Clever or Calculated?");
dialogtitle
.add("Will software development as a skilled profession ever become obsolete and possible by the average person?");
List<String> membername = new ArrayList<String>();
membername.add("By Pegasus");
membername.add("By Andrew");
List<String> postedon = new ArrayList<String>();
postedon.add("6 months ago on Current Affairs");
postedon.add("6 months ago on Current Affairs");
List<Map<String, String>> list = new ArrayList<Map<String, String>>();
Map<String, String> map;
int count = dialogtitle.size();
for (int i = 0; i < dialogtitle.size(); i++) {
map = new HashMap<String, String>();
map.put("dialogtitle", dialogtitle.get(i));
map.put("membername", membername.get(i));
map.put("postedon", postedon.get(i));
list.add(map);
}
tableRowAdapter = new archiveadapter(getActivity(),
R.layout.dialog_archive_list, list);
ListView listView = (ListView) getView().findViewById(R.id.list_view);
listView.setAdapter(tableRowAdapter);
}
}
适配器
public class archiveadapter extends ArrayAdapter< List<Map<String,String>>> {
private final Context context;
private final List<Map<String, String>> names;
private Button deleteButton = null;
public archiveadapter(Context context, int itemResId, List<Map<String,String>> names) {
super(context, itemResId);
this.context = context;
this.names = names;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// LayoutInflater inflater = context.getLayoutInflater();
// View rowView = inflater.inflate(R.layout.mod_req_list, null, true);
View rowView = convertView;
if (rowView == null) {
LayoutInflater inflater = LayoutInflater.from(context);
rowView = inflater.inflate(R.layout.dialog_archive_list, null);
}
TextView archivetitle = (TextView) rowView
.findViewById(R.id.dialogarchive_title);
Map<String, String> map = names.get(position);
//String link = map.get("Link");
archivetitle.setText(map.get("dialogtitle"));
TextView membername = (TextView) rowView.findViewById(R.id.membername);
membername.setText(names.get(1).toString());
TextView votes = (TextView) rowView.findViewById(R.id.postedon);
votes.setText(names.get(2).toString());
return rowView;
}
}
有什么想法或建议吗?谢谢,