Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Minha aplicação da erro ao abrir em um tablet e não consigo identificar o erro ele informa que tenho que habilitar: Unable to start activity ComponentInfo{com.example.everton.horoscopo/com.example.everton.horoscopo.MainActivity}: android.view.InflateException: Binary XML file line #15: Binary XML file line #15: Error inflating class fragment.
Não entendi o erro segue os código se alguém pode me ajudar agradeço esse projeto é para o fim desse mês.
MaindActivity:
package com.example.everton.horoscopo;
public class MainActivity extends AppCompatActivity {
HoroscopoDetailFragment horoscopoDetailFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if(istablet()){
Log.d("Fragment", "entrou!!");
Fragment fragment = new Fragment();
HoroscopoDetailFragment horoscopoDetailFragment = new HoroscopoDetailFragment();
/* FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.frag_detalhe, fragment );
ft.commit();*/
HoroscopoDetailFragment horoscopoDetailFragment1 = new HoroscopoDetailFragment();
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.frag_detalhe, fragment)
.commit(); Toast.makeText(this, "não é Tablet", Toast.LENGTH_SHORT).show();
}
}
private boolean istablet(){
return getResources().getBoolean(R.bool.tablet);
}
private boolean isSmartphone(){
return getResources().getBoolean(R.bool.smartphone);
}
}
Layout do tablet
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.everton.horoscopo.MainActivity">
<fragment
android:layout_width="409dp"
android:layout_height="match_parent"
android:name="com.example.everton.horoscopo.fragments.HoroscopoListFragment"
android:id="@+id/fragmentLista"/>
<fragment
android:layout_width="409dp"
android:layout_height="match_parent"
android:name="com.example.everton.horoscopo.fragments.HoroscopoDetailFragment"
android:id="@+id/fragmentDetail"/>
</RelativeLayout>
Activity do detalhe
package com.example.everton.horoscopo;
public class HoroscopoDetailActivity extends AppCompatActivity {
HoroscopoRepositorio horoscopoRepositorio;
@Overridesuper.onCreate(savedInstanceState);
setContentView(R.layout.activity_horoscopo_item);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
horoscopoRepositorio = new HoroscopoRepositorio(this);
Intent intent = getIntent();
[String](http://www.google.com/search?hl=en&q=allinurl%3AString+java.sun.com&btnI=I%27m%20Feeling%20Lucky) id = intent.getStringExtra("Horosc");
[Cursor](http://www.google.com/search?hl=en&q=allinurl%3ACursor+java.sun.com&btnI=I%27m%20Feeling%20Lucky) cursor = horoscopoRepositorio.consulta(HoroscopoContract._ID + " =" + id);
cursor.moveToFirst();
int icone = cursor.getInt(cursor.getColumnIndex(HoroscopoContract.COL_ICONE));
[String](http://www.google.com/search?hl=en&q=allinurl%3AString+java.sun.com&btnI=I%27m%20Feeling%20Lucky) signo = cursor.getString(cursor.getColumnIndex(HoroscopoContract.COL_SUNSIGN));
ImageView img = (ImageView) findViewById(R.id.detail_icone);
CollapsingToolbarLayout collapser = (CollapsingToolbarLayout) findViewById(R.id.toolbar_layout);
Resources res = this.getResources();
TypedArray logos = res.obtainTypedArray(R.array.logos);
img.setImageDrawable(logos.getDrawable(icone));
collapser.setTitle(signo);
}
}
Fragment do detail
/**
* Created by everton.vasconcelos on 23/09/2016.
*/
public class HoroscopoDetailFragment extends Fragment {
HoroscopoRepositorio horoscopoRepositorio;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
[View](http://www.google.com/search?hl=en&q=allinurl%3AView+java.sun.com&btnI=I%27m%20Feeling%20Lucky) view = inflater.inflate(R.layout.fragment_detail, container, false);
horoscopoRepositorio = new HoroscopoRepositorio(getActivity());
Intent intent = getActivity().getIntent();
[String](http://www.google.com/search?hl=en&q=allinurl%3AString+java.sun.com&btnI=I%27m%20Feeling%20Lucky) id = intent.getStringExtra("Horosc");
[Cursor](http://www.google.com/search?hl=en&q=allinurl%3ACursor+java.sun.com&btnI=I%27m%20Feeling%20Lucky) cursor = horoscopoRepositorio.consulta(HoroscopoContract._ID + " =" + id);
cursor.moveToFirst();
[String](http://www.google.com/search?hl=en&q=allinurl%3AString+java.sun.com&btnI=I%27m%20Feeling%20Lucky) msg = cursor.getString(cursor.getColumnIndex(HoroscopoContract.COL_MESSAGEM));
[String](http://www.google.com/search?hl=en&q=allinurl%3AString+java.sun.com&btnI=I%27m%20Feeling%20Lucky) data = cursor.getString(cursor.getColumnIndex(HoroscopoContract.COL_DATA));
TextView txtData = (TextView) view.findViewById(R.id.frag_item_data);
TextView msge = (TextView) view.findViewById(R.id.frag_item_msg);
msge.setText(msg);
txtData.setText(data);
return view;
}
}
Layout do detail fragment
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".HoroscopoDetailActivity"
android:background="@color/black"
tools:showIn="@layout/activity_horoscopo_item">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:id="@+id/horosc_detalhe"
android:padding="10dp">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.example.everton.horoscopo.fragments.HoroscopoDetailFragment"
android:id="@+id/frag_detalhe"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
No smartphone funciona só da erro ao chamar o layout do tablet.
Carregando comentários...