I am trying to make a chat app so i take the message from the user and then put in the adapter so my xml file

<LinearLayout      xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="wrap_content"
android:layout_height="wrap_content"
 >

 <ListView
    android:layout_width="wrap_content"
    android:layout_height="455dp"
    android:stackFromBottom="true"
    android:transcriptMode="alwaysScroll"
    android:id="@+id/list"></ListView>
<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <EditText
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:id="@+id/text"
        android:layout_alignParentBottom="true"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/text"
        android:layout_alignParentBottom="true"
        android:id="@+id/send"
        android:background="@mipmap/back"
        android:onClick="send"
        />
</RelativeLayout>
 </LinearLayout>

for each item

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:id="@+id/msgl"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:background="@drawable/text"
        android:text="Hi there how are you"
        android:textColor="#000"
        android:layout_alignParentLeft="true"/>

</RelativeLayout>
</LinearLayout>

My main activity

  public class MainActivity extends ActionBarActivity {
   ListView list;
   Button send;
   EditText text;
   TextView time;

   TextView msgl;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.listview);
    send = (Button) findViewById(R.id.send);
    list= (ListView) findViewById(R.id.list);
    text = (EditText) findViewById(R.id.text);
    time = (TextView) findViewById(R.id.time);

    msgl = (TextView) findViewById(R.id.msgl);
   }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    MenuInflater inflater = getMenuInflater();
    getMenuInflater().inflate(R.menu.menu_main, menu);
      return true;
   }

   @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();


    return super.onOptionsItemSelected(item);
  }
public  void send()
  {
   String Message =text.getText().toString();
   list.setAdapter(new listadapter(Message ));

   }

 }

BaseAdapter public class listadapter extends BaseAdapter {

  private Context context;
  private LayoutInflater layinf;
  String message;
  public listadapter(String msgleft)
   {
   message= msgleft;
   }

    public int getCount(){
   return 0;
   }
    public Object getItem(int arg0){
    return 0;
    }
    public long getItemId(int position){
     return 0;
    }
    public View getView(int position,View convertView, ViewGroup parent )
    {
    if(convertView==null){
    convertView =         LayoutInflater.from(context).inflate(R.layout.listview,parent);}
    TextView txt= (TextView)convertView.findViewById(R.id.msgl);
    txt.setText(message);
      return convertView;
      }
    }

and this the error i get so please help

 libcore.io.ErrnoException: close failed: EBADF (Bad file number)
        at libcore.io.Posix.close(Native Method)
        at libcore.io.BlockGuardOs.close(BlockGuardOs.java:75)
        at   com.android.internal.os.ZygoteInit.closeServerSocket(ZygoteInit.java:198)
        at com.android.internal.os.ZygoteConnection.handleChildProc(ZygoteConnection.java:879)
        at com.android.internal.os.ZygoteConnection.runOnce(ZygoteConnection.java:242)
        at com.android.internal.os.ZygoteInit.runSelectLoop(ZygoteInit.java:662)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:598)
        at dalvik.system.NativeStart.main(Native Method)

Related posts

Recent Viewed