0
You can only access a menu ListView
who is without the ActionBar
by the menu key in the emulator.
How to display it? It is necessary to inflate by BaseAdapter
?
Activity
of ListView
:
public class ListDespesasActivity extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
DespesaDAO despesa = new DespesaDAO(this);
List<Despesa> list = despesa.getLista();
ListView listView = getListView();
setListAdapter(new DespesaAdapter(this,list,listView));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_list_despesas, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
case R.id.action_add_despesa:
Intent intent = new Intent(this, EditaDespesaActivity.class);
startActivity(intent);
return true;
}
return super.onOptionsItemSelected(item);
}
}
BaseAdapter
:
public class DespesaAdapter extends BaseAdapter {
private Context context;
private List<Despesa> lista;
private ListView listView;
public DespesaAdapter(Context context, List<Despesa> lista, ListView listView) {
this.context = context;
this.lista = lista;
this.listView = listView;
}
@Override
public int getCount() {
return lista.size();
}
@Override
public Object getItem(int position) {
return lista.get(position);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int position, View view, ViewGroup viewGroup) {
final int auxPosition = position;
LayoutInflater inflater = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final RelativeLayout layout = (RelativeLayout)
inflater.inflate(R.layout.row, null);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent = new Intent(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>
Allan, could include your Manifest and your style file?
– Wakim
Manifest included, what would be the collection of styles? @Wakim
– Allan Chrystian
The archive
styles.xml
.– Wakim
Edited with Styles.xml @Wakim
– Allan Chrystian
I would recommend changing your superclass
Activity
forActionBarActivity
, but this will cause some methods to be unavailable (e. g:setListAdapter
) but then you just copy and implement it yourself (http://answall.com/questions/38337/addir-bot%C3%B5es-na-action-bar-quando-usa-listactivity/39384#39384).– Wakim