0
I have a Listview but only one line is appearing, and I am registering 5 data (item 1, item 2...) Does anyone know what’s going on and what I can do?
Java activity.
public class HomeOrcamentoActivity extends Activity {
private ListView lv1;
private String lv_arr[] = {"Item 1", "Item 2", "Item 3", "Item 4", "Item 5"};
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_home_orcamento);
lv1 = (ListView) findViewById(R.id.listView);
lv1.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, lv_arr));
lv1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
switch( position )
{
case 0: Intent newActivity = new Intent(HomeOrcamentoActivity.this, HomeReformasEReparosActivity.class);
startActivity(newActivity);
break;
case 1: Intent newActivity2 = new Intent(HomeOrcamentoActivity.this, WelcomeActivity.class);
startActivity(newActivity2);
break;
}
}
});
}
}
Activity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#F3F3F3">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/listView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
Thank you, Ramaral. It worked!
– Gabriel Rossetto