开发者

My activity is FORCE CLOSING as soon as i run.. I have used a ListActivity and created a custom adapter

This is my .java file:

    public class List1 extends ListActivity {
    /** Called when the activity is first created. */

    ListView lv1;
    private ArrayList<Tree> m_orders;
    private TreeAdapter m_adapter;

     @Override
    public void onCreate(Bundle savedInstanceState) {

         super.onCreate(savedInstanceState);
         setContentView(R.layout.main);
         getItems();
         this.m_adapter = new TreeAdapter(this, R.layout.row, m_orders);
         s开发者_开发知识库etListAdapter(this.m_adapter);


        }
     public void getItems()
        {
          m_orders=new ArrayList<Tree>();   
          Tree t=new Tree();
          t.setItemName("Document");
          m_orders.add(t);

          t.setItemName("Address Book");
          m_orders.add(t);

        }

}

         class TreeAdapter extends ArrayAdapter<Tree>
    {
    private ArrayList<Tree> it;
        public TreeAdapter(Context context, int textViewResourceId,ArrayList<Tree> items) 
    {
                super(context, textViewResourceId, items);
                this.it=items;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.row, null);

        }

        Tree o = it.get(position);

        if (o != null) {
            TextView tt = (TextView) v.findViewById(R.id.toptext);
            Button btn = (Button)v.findViewById(R.id.theButton);
            if (tt != null) {
                tt.setText("Name is " + o.getItemName());
            }
            if(btn!=null){
                btn.setTag(o);
                btn.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                    Tree o = (Tree)v.getTag();
                    String message = o.getItemName() + " clicked";
                        Toast.makeText(getContext(), message, Toast.LENGTH_LONG).show();
                    }
                });
            }
        }
        return v;
    }

}

In row.xml i have

LinearLayout

-> Checkbox

-> Button

-> TextView

In main.xml i did

LinearLayout

-> ListView

-> TextView

I am getting this in my LOGCAT:

FATAL EXCEPTION:

UNABLE TO START ACTIVITY COMPONENT.INFO


One thing that might be tripping you up is that the xml layout for a ListActivity must include a ListView with android:id="@android:id/list" but it's hard to tell if that is the issue without your main.xml file and the stack trace.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜