Skip to content

Instantly share code, notes, and snippets.

@shobotch
Created December 23, 2013 09:11
Show Gist options
  • Save shobotch/8093850 to your computer and use it in GitHub Desktop.
Save shobotch/8093850 to your computer and use it in GitHub Desktop.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10" />
<EditText
android:id="@+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10" />
<EditText
android:id="@+id/editText4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
package ws.temp.dustcode;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
public class MainActivity extends Activity {
private ArrayAdapter<String[]> adapter;
private EditText[] editText = new EditText[4];
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView listView = (ListView) findViewById(R.id.listView1);
adapter = new ArrayAdapter<String[]>(this, R.layout.m_list) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null)
convertView = getLayoutInflater().inflate(R.layout.m_list,
null);
String[] item = getItem(position);
TextView[] textViews = new TextView[4];
textViews[0] = (TextView) convertView
.findViewById(R.id.textView1);
textViews[1] = (TextView) convertView
.findViewById(R.id.textView2);
textViews[2] = (TextView) convertView
.findViewById(R.id.textView3);
textViews[3] = (TextView) convertView
.findViewById(R.id.textView4);
for (int i = 0; i < textViews.length; i++)
textViews[i].setText(item[i]);
return convertView;
}
};
listView.setAdapter(adapter);
editText[0] = (EditText) findViewById(R.id.editText1);
editText[1] = (EditText) findViewById(R.id.editText2);
editText[2] = (EditText) findViewById(R.id.editText3);
editText[3] = (EditText) findViewById(R.id.editText4);
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String[] tex = new String[4];
for (int i = 0; i < editText.length; i++)
tex[i] = editText[i].getText().toString();
adapter.add(tex);
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment