1
I am running my app, however it returns the following error:
Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class android.widget.ListView
And I’m simply running the App and opening my Listview directly with a button..
Mainactivity
public class MainActivity extends Activity {
ListView listaPrincipal;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listaPrincipal = (ListView) findViewById(R.id.lstPrincipal);
}
public void adicionarVaga(View view){
Intent intent = new Intent(MainActivity.this, VagasActivity.class);
startActivity(intent);
}
public void alterarVaga(View view){
Intent intent = new Intent(MainActivity.this, AlterarVagas.class);
startActivity(intent);
}
}
Activity_main.xml
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/lstPrincipal"
android:clickable="true"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_above="@+id/btAddVaga"
android:onClick="alterarVaga"
android:layout_alignRight="@+id/gridLayout"
android:layout_alignEnd="@+id/gridLayout" />
<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnCount="9"
android:rowCount="2"
android:id="@+id/gridLayout">
<TextView
android:id="@+id/txtNumeroVaga"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:clickable="true"
android:text="ID"
android:layout_row="0"
android:layout_column="0" />
<TextView
android:id="@+id/txtPropretarioVaga"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:clickable="true"
android:text="Ocupante Atual"
android:layout_row="0"
android:layout_column="7"
android:layout_rowSpan="2" />
</GridLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+"
android:id="@+id/btAddVaga"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:onClick="adicionarVaga"/>
I’d be grateful to demonstrate what’s missing from my code. Thank you
Listview does not work by itself, it needs an Adapter. Are you setting your Adapter? If so, can you post the code for that part? More information in this tutorial: http://blog.alura.com.br/criando-lista-com-listview-no-android/
– Henrod
The xml you posted is all you find on Activity_main.xml?
– ramaral
This XML in Activitymain.xml is either incomplete, or it’s wrong. You can’t have more than a single parent node in android layout XML!
– Loudenvier
Guys, I ended up discovering that the problem was enabling the onClick method without clicks, because the database was still empty. I ended up changing the logic of my database and also the XML in question and I will use the setonItemSelected().. method, thanks for the help. As soon as possible I put the code..
– Gabriel Henrique