text.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="20dp"
android:textColor="##ff2020" >
</TextView>
activity_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity"
android:background="#ff00ff" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#ff00ff" >
</ListView>
</LinearLayout>
public class list extends Activity{
String[] names = { "name1", "name2", "name3", "name4", "name5", "Second Activity", "name7", "name8", "name9", "name10" , "name11", "name12", "name13", "name14", "name15", "name16","name17", "name18", "name19", "name20"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
ListView list = (ListView) findViewById(R.id.listView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.text,names);
list.setAdapter(adapter);
}
}
No comments:
Post a Comment