public class CellatlasMain extends Fragment implements OnClickListener,OnItemClickListener {
ListView listNewView;
List<GetterSetter> arrList;
public static final Integer[] images = { R.drawable.arrow_new,
R.drawable.arrow_new, };
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View v = inflater.inflate(R.layout.cellatlas_main, null);
arrList = new ArrayList<GetterSetter>();
try {
InputStream is = getActivity().getAssets().open("public_material.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(is);
doc.getDocumentElement().normalize();
NodeList nList = doc.getElementsByTagName("inneritem");
for (int i = 0; i < nList.getLength(); i++)
Log.d("List count :- ", "" + nList.getLength());
for (int temp = 0; temp < nList.getLength(); temp++) {
Node GetEementNode = nList.item(temp);
if (GetEementNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) GetEementNode;
String strID = eElement.getAttribute("id");
String Title = eElement.getAttribute("title");
//String Thumbnail = eElement.getAttribute("thumbnail");
// GetterSetter row = new GetterSetter(strID,Title, Thumbnail);
GetterSetter row = new GetterSetter(strID,Title);
arrList.add(row);
}
}
} catch (Exception e) {
}
listNewView = (ListView) v.findViewById(R.id.listview);
BaseAdapterData data = new BaseAdapterData(getActivity(), arrList);
listNewView.setAdapter(data);
listNewView.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
long arg3) {
// TODO Auto-generated method stub
GetterSetter row_item = arrList.get(pos);
}
});
return v;
}
@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
}
}
答案 0 :(得分:0)
如果要在列表项上打开另一个视图,请单击
试试这个:
// Click event for single list row
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent newsDetails = new Intent(getApplicationContext(),Details.class);
newsDetails .putExtra("position", position);
startActivity(newsDetails);
}
});
并且不要忘记在清单文件中包含Detail
类。