Hello, I want a screen to have a button, and below that button, a list with several items. But it turns out the buttons are multiplied.
See:
activity.xml
<?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"
android:gravity="center_vertical" >
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/nova"
android:onClick="nova"
android:layout_marginTop="20dp"
android:text="@string/nova" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:orientation="vertical">
<TextView
android:id="@+id/nome"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
Activity.java
package com.educin.leonardo.nomes;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class TarefasActivity extends ListActivity implements AdapterView.OnItemClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] de = {"nome"};
int[] para = {R.id.nome};
SimpleAdapter adapter = new SimpleAdapter(this, listarNomes(), R.layout.activity, de, para);
setListAdapter(adapter);
getListView().setOnItemClickListener(this);
}
private List<Map<String, Object>> nomes;
private List<Map<String, Object>> listarNomes() {
nmes = new ArrayList<Map<String, Object>>();
Map<String, Object> item = new HashMap<String, Object>();
item = new HashMap<String, Object>();
item.put("nome", "Leonardo");
nomes.add(item);
item = new HashMap<String, Object>();
item.put("nome", "Leo");
nomes.add(item);
return nome;
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Map<String, Object> map = nomes.get(position);
String nome = (String) map.get("nome");
Toast.makeText(this, nome, Toast.LENGTH_SHORT).show();
}
public void nova(View view) {
if (view.getId() == R.id.nova) {
startActivity(new Intent(this, NovaNovaActivity.class));
}
}
}
Explaining better: Two lines and one button are formed on each line. But I would just like a button at the top of Activity.
How to solve?