android – How to get xml data in listview with textview & imageview in fragment with onclick listener & onitemclick listener with base adapter pls-ThrowExceptions

Exception or error:
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

    }
    }
How to solve:

If you want to open another view on list item click,

try this:

// 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);
    }

});

and don’t forget to include the Detail class in manifest file.

Leave a Reply

Your email address will not be published. Required fields are marked *