2013-11-04 58 views
0

你好,大家好我devlope此聊天屏幕,首先從sqllite和按鈕單擊添加數據記錄到SQL精簡版獲得的數據和dynemically顯示在屏幕上太...
如何添加項目在此基礎adpter的Android

現在,所有的工作數據插入到sqllite但DOAS不會出現在名單..

與基地adpter活動是..

public class Chat_Home extends Activity implements OnClickListener { 

MsgDataSource source; 
EditText editText; 
AnimalAdapter adapter; 
ListView listView; 
List<Msgs> list; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    Button button = (Button) findViewById(R.id.button1); 
    button.setOnClickListener(this); 
    editText = (EditText) findViewById(R.id.editText1); 
    listView = (ListView) findViewById(R.id.list); 
    source = new MsgDataSource(getApplicationContext()); 
    list = new ArrayList<Msgs>(); 

    list = source.getAnimals();//get all msgs from sql lite and save it to list 
    adapter = new AnimalAdapter(list); 
    listView.setAdapter(adapter); 
} 


public class AnimalAdapter extends BaseAdapter { 
    final List<Row> rows; 
    List<Msgs> list=new ArrayList<Msgs>(); 

    public void add(Msgs msgs) { 
     // TODO Auto-generated method stub 
     Log.e("pmmmmm",""+list.size()); 
     list.add(msgs); 
     Log.e("pmmmmm",""+list.size()); 
     notifyDataSetChanged(); 

    } 
    public AnimalAdapter(List<Msgs> msgs) { 
     // TODO Auto-generated constructor stub 
     list.addAll(msgs); 
     rows = new ArrayList<Row>(); 

     String type; 
     for (Msgs msg : list) { 
      Log.e("String", msg.get_sender()); 
      type = msg.get_sender(); 
      if (type.equalsIgnoreCase("me")) { 
       rows.add(new Send_Row(LayoutInflater.from(Chat_Home.this), 
         msg)); 
      } else { 
       rows.add(new Reciv_row(
         LayoutInflater.from(Chat_Home.this), msg)); 
      } 

     } 
    } 

    @Override 
    public int getViewTypeCount() { 
     return RowType.values().length; 
    } 

    @Override 
    public int getItemViewType(int position) { 
     return rows.get(position).getViewType(); 
    } 

    public int getCount() { 
     return rows.size(); 
    } 

    public Object getItem(int position) { 
     return position; 
    } 

    public long getItemId(int position) { 
     return position; 
    } 

    public View getView(int position, View convertView, ViewGroup parent) { 
     return rows.get(position).getView(convertView); 
    } 


} 

@SuppressLint("NewApi") 
@Override 
public void onClick(View arg0) { 

    String msg; 
    msg = editText.getEditableText().toString(); 
    source.addmsg(msg, "text", 888888, "me", 0); 
    adapter.add(new Msgs(msg, "text", 888888, "me", 0)); 
    editText.setText(""); 
} 

項目是添加時添加了Methode被稱爲列出.. PLZ幫助.. 感謝ü提前...

在你的onClick方法

回答

0

做這樣的..

list.add(your new object); 

將它添加後arraylist通過調用

adapter.notifyDataSetChanged(); 
0

刷新listview更改您的final List<Row> rows to public List<Row>,並在notifyDataSetChanged之後添加此收藏品

+0

i alredy嘗試但kalyan pvs m ethod工作.. –

相關問題