Botão no rodape da listView[RESOLVIDO]

8 respostas
E

Bom dia,
Tenho uma lista com dados do banco carregada pelo adapter, e preciso de um botão no rodapé da tela, ao criar o xml e a activity, o botão fica na parte superior da tela e também aparece em todos os itens da lista.
O botao da parte superior executa sua funcao normalmente, ja os botoes que aparecem nos itens da lista nao executam acao nenhuma quando clicados e tambem impedem que se clique os itens da lista.
Alguem pode me ajudar?

meu 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="match_parent"
    android:orientation="vertical"
    android:id="@+id/relativeLayout1" >

    <RelativeLayout
        android:id="@+id/relativeLayout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/txtRegMot"
            android:layout_width="375dp"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:clickable="false"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@android:color/black"
            android:textSize="25dp" />

        <TextView
            android:id="@+id/txtReb"
            android:layout_width="250dp"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/txtRegMot"
            android:clickable="false"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@android:color/black"
            android:textSize="25dp" />

        <TextView
            android:id="@+id/txtJulieta"
            android:layout_width="180dp"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@id/txtRegMot"
            android:clickable="false"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@android:color/black"
            android:textSize="25dp" />

        <TextView
            android:id="@+id/txtFaz"
            android:layout_width="310dp"
            android:layout_height="wrap_content"
            android:layout_below="@id/txtRegMot"
            android:layout_toRightOf="@id/txtJulieta"
            android:clickable="false"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@android:color/black"
            android:textSize="25dp" />

        <TextView
            android:id="@+id/txtQuadra"
            android:layout_width="160dp"
            android:layout_height="wrap_content"
            android:layout_below="@id/txtReb"
            android:layout_toRightOf="@id/txtFaz"
            android:clickable="false"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@android:color/black"
            android:textSize="25dp" />

        <TextView
            android:id="@+id/txtCarregadeira"
            android:layout_width="240dp"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@id/txtJulieta"
            android:clickable="false"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@android:color/black"
            android:textSize="25dp" />

        <TextView
            android:id="@+id/txtCarregador"
            android:layout_width="510dp"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_below="@id/txtQuadra"
            android:layout_toRightOf="@id/txtCarregadeira"
            android:clickable="false"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@android:color/black"
            android:textSize="25dp" />

        <TextView
            android:id="@+id/txtTrator"
            android:layout_width="185dp"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@id/txtCarregadeira"
            android:clickable="false"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@android:color/black"
            android:textSize="25dp" />

        <TextView
            android:id="@+id/txtTratorista"
            android:layout_width="515dp"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_below="@id/txtCarregador"
            android:layout_toRightOf="@id/txtTrator"
            android:clickable="false"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@android:color/black"
            android:textSize="25dp" />

        <TextView
            android:id="@+id/txtData"
            android:layout_width="330dp"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@id/txtTrator"
            android:clickable="false"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@android:color/black"
            android:textSize="25dp" />

        <TextView
            android:id="@+id/txtCanaPicada"
            android:layout_width="250dp"
            android:layout_height="wrap_content"
            android:layout_below="@id/txtTratorista"
            android:layout_toRightOf="@id/txtData"
            android:clickable="false"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@android:color/black"
            android:textSize="25dp" />

        <TextView
            android:id="@+id/txtTransbordo1"
            android:layout_width="270dp"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@id/txtData"
            android:clickable="false"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@android:color/black"
            android:textSize="25dp" />

        <TextView
            android:id="@+id/txtTransbordo2"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_below="@id/txtCanaPicada"
            android:layout_toRightOf="@id/txtTransbordo1"
            android:clickable="false"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@android:color/black"
            android:textSize="25dp" />

        <ListView
            android:id="@+id/listGuia"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:choiceMode="singleChoice" >
        </ListView>
   	</RelativeLayout>
   
    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/listGuia" >

        <Button
            android:id="@+id/btnEnviar"
            android:layout_width="fill_parent"
            android:layout_height="60dp"
            android:paddingTop="10dp"
            android:paddingBottom="10dp"
            android:text="@string/enviar"
            android:textSize="25sp" />
    </LinearLayout>

</RelativeLayout>
e minha activity:
package br.com.guiadecana;

public class ListaActivity extends Activity implements OnItemClickListener{
	
	@SuppressWarnings("unused")
	private LayoutInflater inflater;
	private ListView list;
	private GuiaAdapter guiaAdapter;
	List<Guia> guias = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.lista_guias);
		
		final GuiadeCanaDAO guiadeCanaDAO = new GuiadeCanaDAO(ListaActivity.this);
		final MotoristaDAO motoristaDAO = new MotoristaDAO(ListaActivity.this);
		final GuiadeCanaWS guiadeCanaWS = new GuiadeCanaWS();
		
		inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
		list = (ListView) findViewById(R.id.listGuia);
		list.setOnItemClickListener(ListaActivity.this);
		carregarLista();
		
		//BOTÃO PARA ENVIAR OS DADOS
		Button btnEnviar = (Button) findViewById(R.id.btnEnviar);
		btnEnviar.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				pdAguarde = ProgressDialog.show(ListaActivity.this, "SINCRONIZAÇÃO", "ENVIANDO DADOS. AGUARDE...");
				try {
					new Thread(){
						public void run() {
							try {
								Timestamp envio = new Timestamp(new Date(System.currentTimeMillis()).getTime());
								guiadeCanaWS.inserir(guiadeCanaDAO.listaGuias(), motoristaDAO.getEmpresa());
								guiadeCanaDAO.atualizaEnvioServidor(envio);
								GuiadeCanaActivity.operacao = true;
								
								enviaMessageDialogThread("GUIA DE CANA", "INFORMAÇÕES ENVIADAS COM SUCESSO");
								
							} catch (Exception e) {
								e.printStackTrace();
								enviaMessageDialogThread("ERRO","HOUVE ERRO NA SINCRONIZAÇÃO. \n DETALHES: " + e.getMessage());
							}
							pdAguarde.dismiss();
						}						
					}.start();
					
				} catch (Exception e) {
					enviaMessageDialogThread("ERRO","HOUVE ERRO NA SINCRONIZAÇÃO. \n DETALHES: " + e.getMessage());
				}
				
			}
		});
	}
	
	public void onItemClick(AdapterView<?> l, final View v, final int position, final long id) {
		AlertDialog.Builder dialog = new AlertDialog.Builder(ListaActivity.this);
		dialog.setTitle("GUIA");
		dialog.setMessage("DESEJA CORRIGIR ESSA GUIA");
		dialog.setPositiveButton("SIM", new DialogInterface.OnClickListener() {
			@Override
			//Verifica se preencheu o estoque inicial
			public void onClick(DialogInterface arg0, int arg1) {
			Intent itGuias =  new Intent(ListaActivity.this, 
										 GuiaActivity.class);
			Guia g = guias.get(position);
			int num = g.getiNumeroControle();
			GuiaActivity.operacao = false;
			itGuias.putExtra("numero_controle", num);
			startActivity(itGuias);
			finish();
			}
		});
		dialog.setNegativeButton("NÃO", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface arg0, int arg1) {
				// Continua na tela
			}
		});
		dialog.show();
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		carregarLista();
	}
	
	private void carregarLista(){
		GuiadeCanaDAO guiaDAO = new GuiadeCanaDAO(ListaActivity.this);
		guias = guiaDAO.listaGuias();
		System.out.println("Guiasss lista no dao>>>>>>>>>>>>>>" + guias);
		guiaAdapter = new GuiaAdapter(ListaActivity.this, guias);
		System.out.println("Guiass no adapter::::::::::" + guiaAdapter);
		list.setAdapter(guiaAdapter);
	}
}

8 Respostas

L

Cara eu não vi botão nenhum nos itens da lista…

Mas procure sobre Custom ListView E crie a sua listView com os botões do lado!! Não é difcil!!

Se você estiver com muita dificuldade da um toque aqui que te dou uma força… Mas tenta ai!!

E

o botão eh a ultima coisa do xml, vou dar uma pesquisada no custom listview, mas não sei se eh viável, esse layout precisa ser extremamente simples.

L

Mas então esse botão não fica em todos os itens… é o ultimo item não é?

E

esse e meu problema, o botao mesmo estando em um layout separado se repete em todos os itens da minha lista.

L

Aah saquei!! Vc não explica hahaha pensei que você tinha colocado botões em todas as coisas!!

Pior que não tem como eu testar seu projeto pois não tenho ele;…

Tenta tirar do linear layout e colocar no relative… ve oq da!!

sei la… Esse é um caso muito especifico!!

Vou fazer um teste aqui com seu XML e daqui a pouco eu falo oq deu!!!

E

Ja tentei dos as variacoes de layout possivel, acho q deve ser algo na activity…

L

Cara pode ser algo no seu código pq eu fiz o teste com o seu xml e olha como ficou!!!

<?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="match_parent"  
    android:orientation="vertical"  
    android:id="@+id/relativeLayout1" >  
  
    <RelativeLayout  
        android:id="@+id/relativeLayout2"  
        android:layout_width="match_parent"  
        android:layout_height="wrap_content" >  
  
        <TextView  
            android:id="@+id/txtRegMot"  
            android:layout_width="375dp"  
            android:layout_height="wrap_content"  
            android:layout_alignParentLeft="true"  
            android:clickable="false"  
            android:focusable="false"  
            android:focusableInTouchMode="false"  
            android:textAppearance="?android:attr/textAppearanceMedium"  
            android:textColor="@android:color/black"  
            android:textSize="25dp" />  
  
        <TextView  
            android:id="@+id/txtReb"  
            android:layout_width="250dp"  
            android:layout_height="wrap_content"  
            android:layout_toRightOf="@id/txtRegMot"  
            android:clickable="false"  
            android:focusable="false"  
            android:focusableInTouchMode="false"  
            android:textAppearance="?android:attr/textAppearanceMedium"  
            android:textColor="@android:color/black"  
            android:textSize="25dp" />  
  
        <TextView  
            android:id="@+id/txtJulieta"  
            android:layout_width="180dp"  
            android:layout_height="wrap_content"  
            android:layout_alignParentLeft="true"  
            android:layout_below="@id/txtRegMot"  
            android:clickable="false"  
            android:focusable="false"  
            android:focusableInTouchMode="false"  
            android:textAppearance="?android:attr/textAppearanceMedium"  
            android:textColor="@android:color/black"  
            android:textSize="25dp" />  
  
        <TextView  
            android:id="@+id/txtFaz"  
            android:layout_width="310dp"  
            android:layout_height="wrap_content"  
            android:layout_below="@id/txtRegMot"  
            android:layout_toRightOf="@id/txtJulieta"  
            android:clickable="false"  
            android:focusable="false"  
            android:focusableInTouchMode="false"  
            android:textAppearance="?android:attr/textAppearanceMedium"  
            android:textColor="@android:color/black"  
            android:textSize="25dp" />  
  
        <TextView  
            android:id="@+id/txtQuadra"  
            android:layout_width="160dp"  
            android:layout_height="wrap_content"  
            android:layout_below="@id/txtReb"  
            android:layout_toRightOf="@id/txtFaz"  
            android:clickable="false"  
            android:focusable="false"  
            android:focusableInTouchMode="false"  
            android:textAppearance="?android:attr/textAppearanceMedium"  
            android:textColor="@android:color/black"  
            android:textSize="25dp" />  
  
        <TextView  
            android:id="@+id/txtCarregadeira"  
            android:layout_width="240dp"  
            android:layout_height="wrap_content"  
            android:layout_alignParentLeft="true"  
            android:layout_below="@id/txtJulieta"  
            android:clickable="false"  
            android:focusable="false"  
            android:focusableInTouchMode="false"  
            android:textAppearance="?android:attr/textAppearanceMedium"  
            android:textColor="@android:color/black"  
            android:textSize="25dp" />  
  
        <TextView  
            android:id="@+id/txtCarregador"  
            android:layout_width="510dp"  
            android:layout_height="wrap_content"  
            android:layout_alignParentRight="true"  
            android:layout_below="@id/txtQuadra"  
            android:layout_toRightOf="@id/txtCarregadeira"  
            android:clickable="false"  
            android:focusable="false"  
            android:focusableInTouchMode="false"  
            android:textAppearance="?android:attr/textAppearanceMedium"  
            android:textColor="@android:color/black"  
            android:textSize="25dp" />  
  
        <TextView  
            android:id="@+id/txtTrator"  
            android:layout_width="185dp"  
            android:layout_height="wrap_content"  
            android:layout_alignParentLeft="true"  
            android:layout_below="@id/txtCarregadeira"  
            android:clickable="false"  
            android:focusable="false"  
            android:focusableInTouchMode="false"  
            android:textAppearance="?android:attr/textAppearanceMedium"  
            android:textColor="@android:color/black"  
            android:textSize="25dp" />  
  
        <TextView  
            android:id="@+id/txtTratorista"  
            android:layout_width="515dp"  
            android:layout_height="wrap_content"  
            android:layout_alignParentRight="true"  
            android:layout_below="@id/txtCarregador"  
            android:layout_toRightOf="@id/txtTrator"  
            android:clickable="false"  
            android:focusable="false"  
            android:focusableInTouchMode="false"  
            android:textAppearance="?android:attr/textAppearanceMedium"  
            android:textColor="@android:color/black"  
            android:textSize="25dp" />  
  
        <TextView  
            android:id="@+id/txtData"  
            android:layout_width="330dp"  
            android:layout_height="wrap_content"  
            android:layout_alignParentLeft="true"  
            android:layout_below="@id/txtTrator"  
            android:clickable="false"  
            android:focusable="false"  
            android:focusableInTouchMode="false"  
            android:textAppearance="?android:attr/textAppearanceMedium"  
            android:textColor="@android:color/black"  
            android:textSize="25dp" />  
  
        <TextView  
            android:id="@+id/txtCanaPicada"  
            android:layout_width="250dp"  
            android:layout_height="wrap_content"  
            android:layout_below="@id/txtTratorista"  
            android:layout_toRightOf="@id/txtData"  
            android:clickable="false"  
            android:focusable="false"  
            android:focusableInTouchMode="false"  
            android:textAppearance="?android:attr/textAppearanceMedium"  
            android:textColor="@android:color/black"  
            android:textSize="25dp" />  
  
        <TextView  
            android:id="@+id/txtTransbordo1"  
            android:layout_width="270dp"  
            android:layout_height="wrap_content"  
            android:layout_alignParentLeft="true"  
            android:layout_below="@id/txtData"  
            android:clickable="false"  
            android:focusable="false"  
            android:focusableInTouchMode="false"  
            android:textAppearance="?android:attr/textAppearanceMedium"  
            android:textColor="@android:color/black"  
            android:textSize="25dp" />  
  
        <TextView  
            android:id="@+id/txtTransbordo2"  
            android:layout_width="200dp"  
            android:layout_height="wrap_content"  
            android:layout_alignParentRight="true"  
            android:layout_below="@id/txtCanaPicada"  
            android:layout_toRightOf="@id/txtTransbordo1"  
            android:clickable="false"  
            android:focusable="false"  
            android:focusableInTouchMode="false"  
            android:textAppearance="?android:attr/textAppearanceMedium"  
            android:textColor="@android:color/black"  
            android:textSize="25dp" />  
  
        <ListView  
            android:id="@+id/listGuia"  
            android:layout_width="fill_parent"  
            android:layout_height="wrap_content"  
            android:layout_alignParentLeft="true"  
            android:layout_alignParentTop="true"  
            android:choiceMode="singleChoice" >  
        </ListView>  
    </RelativeLayout>  
     
    <LinearLayout  
        android:id="@+id/linearLayout1"  
        android:layout_width="match_parent"  
        android:layout_height="fill_parent"  
        android:layout_alignParentBottom="true"  
        android:layout_alignParentRight="true"  
        android:layout_below="@+id/listGuia" >  
  
        <Button  
            android:id="@+id/btnEnviar"  
            android:layout_width="fill_parent"  
            android:layout_height="60dp"  
            android:paddingTop="10dp"  
            android:paddingBottom="10dp"  
            android:textSize="25sp" />  
    </LinearLayout>  
  
</RelativeLayout>

Activity

package com.example.teste5;


import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		ListView lista = (ListView) findViewById(R.id.listGuia);
		
		String City[] = { "São Paulo", "Santos" , "Acre", "Santa Catarina"};
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this,
				android.R.layout.simple_list_item_1, City);
		lista.setAdapter(adapter);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}


E

Resolvi o problema deixando o XML apenas com a lista e criando os botoes através de um footer view na própria activity.

Criado 1 de março de 2013
Ultima resposta 4 de mar. de 2013
Respostas 8
Participantes 2