Created
February 8, 2012 17:29
-
-
Save aquilax/1771481 to your computer and use it in GitHub Desktop.
Add to list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.avtobiografia.list_test; | |
import java.util.ArrayList; | |
import java.util.List; | |
import android.app.Activity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.ArrayAdapter; | |
import android.widget.Button; | |
import android.widget.EditText; | |
import android.widget.ListView; | |
public class List_testActivity extends Activity { | |
List<String> model=new ArrayList<String>(); | |
ArrayAdapter<String> adapter=null; | |
/** Called when the activity is first created. */ | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.main); | |
Button save=(Button)findViewById(R.id.add); | |
save.setOnClickListener(onSave); | |
ListView list=(ListView)findViewById(R.id.list_view); | |
adapter = new ArrayAdapter<String>(this, | |
android.R.layout.simple_list_item_1, | |
model); | |
list.setAdapter(adapter); | |
} | |
private View.OnClickListener onSave=new View.OnClickListener() { | |
public void onClick(View v) { | |
EditText name = (EditText)findViewById(R.id.edit); | |
adapter.add(name.getText().toString()); | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment