You can only access the menu of a ListView
that is without ActionBar
by the menu key in the emulator.
How to display it? Do you need to inflate by BaseAdapter
?
Activity
ofListView
:
publicclassListDespesasActivityextendsListActivity{@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);DespesaDAOdespesa=newDespesaDAO(this);List<Despesa>list=despesa.getLista();ListViewlistView=getListView();setListAdapter(newDespesaAdapter(this,list,listView));}@OverridepublicbooleanonCreateOptionsMenu(Menumenu){getMenuInflater().inflate(R.menu.menu_list_despesas,menu);returntrue;}@OverridepublicbooleanonOptionsItemSelected(MenuItemitem){switch(item.getItemId()){caseandroid.R.id.home:NavUtils.navigateUpFromSameTask(this);returntrue;caseR.id.action_add_despesa:Intentintent=newIntent(this,EditaDespesaActivity.class);startActivity(intent);returntrue;}returnsuper.onOptionsItemSelected(item);}}
BaseAdapter
:
publicclassDespesaAdapterextendsBaseAdapter{privateContextcontext;privateList<Despesa>lista;privateListViewlistView;publicDespesaAdapter(Contextcontext,List<Despesa>lista,ListViewlistView){this.context=context;this.lista=lista;this.listView=listView;}@OverridepublicintgetCount(){returnlista.size();}@OverridepublicObjectgetItem(intposition){returnlista.get(position);}@OverridepubliclonggetItemId(inti){returni;}@OverridepublicViewgetView(intposition,Viewview,ViewGroupviewGroup){finalintauxPosition=position;LayoutInflaterinflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);finalRelativeLayoutlayout=(RelativeLayout)inflater.inflate(R.layout.row,null);listView.setOnItemClickListener(newAdapterView.OnItemClickListener(){@OverridepublicvoidonItemClick(AdapterView<?>adapterView,Viewview,inti,longl){Intentintent=newIntent(context,EditaDespesaActivity.class);intent.putExtra("valor", lista.get(auxPosition).getValor());
intent.putExtra("data", lista.get(auxPosition).getData());
intent.putExtra("descricao", lista.get(auxPosition).getDescricao());
context.startActivity(intent);
}
});
TextView data = (TextView)
layout.findViewById(R.id.ddata);
data.setText(lista.get(position).getData());
TextView desc = (TextView)
layout.findViewById(R.id.ddesc);
desc.setText(lista.get(position).getDescricao());
TextView valor = (TextView)
layout.findViewById(R.id.vvalor);
valor.setText(lista.get(position).getValor());
return layout;
}
}
Manifest.xml
:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.prjctt.allan.financeiro" >
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".EditaDespesaActivity"
android:label="@string/title_activity_edita_despesa"
android:parentActivityName=".ListDespesasActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ListDespesasActivity" />
</activity>
<activity
android:name=".ListDespesasActivity"
android:label="@string/title_activity_despesas"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".EditaReceitaActivity"
android:label="@string/title_activity_edita_receita" >
</activity>
</application>
Styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>