As u can see there is some text missing in some CardView
I am trying to simply make TextView appear inside a CardView.All I need to do is make texts appear inside the CardView.The CardView appear, but some CardView do not show any text inside them.
item_names.xml
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardCornerRadius="5dp"
android:elevation="5dp"
android:layout_margin="5dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/numberCount"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" />
<TextView
android:id="#+id/tvName"
android:layout_below="#+id/numberCount"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" />
<TextView
android:id="#+id/arabicName"
android:layout_below="#+id/tvName"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" />
<TextView
android:id="#+id/meaning"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/arabicName"
android:gravity="center"/>
</RelativeLayout>
activity_allah_names.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:fitsSystemWindows="true"
tools:context="com.islamiclearn.namesofallah.activity.AllahNamesActivity">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/ad_view1"
android:layout_alignParentTop="true"
android:id="#+id/rcv"/>
<com.google.android.gms.ads.AdView
android:id="#+id/ad_view1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
ads:adUnitId="#string/banner_ad_unit_id"
android:layout_alignParentBottom="true"/>
AllahNamesActivity.java
public class AllahNamesActivity extends AppCompatActivity {
private List<Names> list;
private RecyclerView mRecyclerView;
private AdView mAdView1;
/*
Intent communicate b/w Android components like Activity,
Service, Broadcast
*/
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_allah_names);
MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713");
mAdView1 = (AdView) findViewById(R.id.ad_view1);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
// Start loading the ad in the background.
mAdView1.loadAd(adRequest);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mRecyclerView = (RecyclerView) findViewById(R.id.rcv);
getNames();
mRecyclerView.addOnItemTouchListener(new RecyclerItemClickListener(this, new RecyclerItemClickListener.OnItemClickListener() {
#Override
public void onItemClick(View view, int position) {
Intent intent = new Intent(AllahNamesActivity.this, SecondActivity.class);
Bundle bundle = new Bundle();
bundle.putInt("Position", position);
bundle.putParcelableArrayList("LIST", (ArrayList<Names>) list);
intent.putExtras(bundle);
startActivity(intent);
}
}));
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
}
return super.onOptionsItemSelected(item);
}
private void getNames() {
new AsyncTask<Void, Void, List<Names>>() {
#Override
protected List<Names> doInBackground(Void... params) {
return fillArray();
}
#Override
protected void onPostExecute(List<Names> names) {
super.onPostExecute(names);
if (names != null && names.size() > 0) {
list = names;
mRecyclerView.setLayoutManager(new GridLayoutManager(AllahNamesActivity.this, 2));
mRecyclerView.setAdapter(new NamesAdapter(list));
}
}
}.execute();
}
private List<Names> fillArray() {
String[] arraCount = getResources().getStringArray(item_count);
String[] arra = getResources().getStringArray(names);
String[] arraArabic = getResources().getStringArray(R.array.names_arabic);
String[] arraMeaning = getResources().getStringArray(R.array.meaning);
String[] music = getResources().getStringArray(R.array.music);
List<Names> namesList = new ArrayList<>();
for (int i = 0; i < arra.length; i++) {
Names names = new Names();
names.setCount(arraCount[i]);
names.setName(arra[i]);
names.setArabicName(arraArabic[i]);
names.setMeaning(arraMeaning[i]);
int resID = getId(music[i]);
names.setResId(resID);
namesList.add(names);
}
Items items = new Items();
List<String> list = new ArrayList<>();
items.setArabicList(list);
return namesList;
}
public int getId(String resName) {
return getResources().getIdentifier(resName,
"raw", getPackageName());
}
}
arrays.xml
<resources>
<string-array name="item_count">
<item>"1"</item>
<item>"2"</item>
<item>"3"</item>
<item>"4"</item>
<item>"5"</item>
<item>"6"</item>
<item>"7"</item>
<item>"8"</item>
<item>"9"</item>
<item>"10"</item>
<item>"11"</item>
<item>"12"</item>
<item>"13"</item>
<item>"14"</item>
<item>"15"</item>
<item>"16"</item>
<item>"17"</item>
<item>"18"</item>
<item>"19"</item>
<item>"20"</item>
<item>"21"</item>
<item>"22"</item>
<item>"23"</item>
<item>"24"</item>
<item>"25"</item>
<item>"26"</item>
<item>"27"</item>
<item>"28"</item>
<item>"29"</item>
<item>"30"</item>
<item>"31"</item>
<item>"32"</item>
<item>"33"</item>
<item>"34"</item>
<item>"35"</item>
<item>"36"</item>
<item>"37"</item>
<item>"38"</item>
<item>"39"</item>
<item>"40"</item>
<item>"41"</item>
<item>"42"</item>
<item>"43"</item>
<item>"44"</item>
<item>"45"</item>
<item>"46"</item>
<item>"47"</item>
<item>"48"</item>
<item>"49"</item>
<item>"50"</item>
<item>"51"</item>
<item>"52"</item>
<item>"53"</item>
<item>"54"</item>
<item>"55"</item>
<item>"56"</item>
<item>"57"</item>
<item>"58"</item>
<item>"59"</item>
<item>"60"</item>
<item>"61"</item>
<item>"62"</item>
<item>"63"</item>
<item>"64"</item>
<item>"65"</item>
<item>"66"</item>
<item>"67"</item>
<item>"68"</item>
<item>"69"</item>
<item>"70"</item>
<item>"71"</item>
<item>"72"</item>
<item>"73"</item>
<item>"74"</item>
<item>"75"</item>
<item>"76"</item>
<item>"77"</item>
<item>"78"</item>
<item>"79"</item>
<item>"80"</item>
<item>"81"</item>
<item>"82"</item>
<item>"83"</item>
<item>"84"</item>
<item>"85"</item>
<item>"86"</item>
<item>"87"</item>
<item>"88"</item>
<item>"89"</item>
<item>"90"</item>
<item>"91"</item>
<item>"92"</item>
<item>"93"</item>
<item>"94"</item>
<item>"95"</item>
<item>"96"</item>
<item>"97"</item>
<item>"98"</item>
<item>"99"</item>
</string-array>
<string-array name="names">
<item>Ar-Rahman</item>
<item>\'Ar-Rahim</item>
<item>Al-Malik</item>
<item> Al-Quddus</item>
<item>As-Salam</item>
<item>Al-Mu\'min</item>
<item>Al-Muhaymin</item>
<item>Al-Aziz</item>
<item>Al-Jabbar</item>
<item>Al-Mutakabbir</item>
<item>Al-Khaliq</item>
<item> Al-Bari\'</item>
<item>Al-Musawwir</item>
<item>Al-Ghaffar</item>
<item>Al-Qahhar </item>
<item>Al-Wahhab</item>
<item>Ar-Razzaq</item>
<item>Al-Fattah</item>
<item>Al-\'Alim</item>
<item>Al-Qabid</item>
<item>Al-Basit</item>
<item>Al-Khafid</item>
<item>Ar-Rafi</item>
<item>Al-Mu\'izz</item>
<item>Al-Mudhill</item>
<item>As-Sami</item>
<item>Al-Basir</item>
<item>Al-Hakam</item>
<item>Al-\'Adl</item>
<item>Al-Latif</item>
<item>Al-Khabir</item>
<item>Al-Halim</item>
<item>Al-Azim</item>
<item>Al-Ghafur</item>
<item>Ash-Shakur</item>
<item>Al-Ali</item>
<item>Al-Kabir</item>
<item>Al-Hafiz</item>
<item>Al-Muqit</item>
<item>Al-Hasib</item>
<item>Al-Jalil</item>
<item>Al-Karim</item>
<item>Ar-Raqib</item>
<item>Al-Mujib</item>
<item>Al-Wasi</item>
<item>Al-Hakim</item>
<item>Al-Wadud</item>
<item>Al-Majid</item>
<item>Al-Ba\'ith</item>
<item>Ash-Shahid</item>
<item>Al-Haqq</item>
<item>Al-Wakil</item>
<item>Al-Qawiyy</item>
<item>Al-Matin</item>
<item>Al-Waliyy</item>
<item>Al-Hamid</item>
<item>Al-Muhsi</item>
<item>Al-Mubdi\'</item>
<item>Al-Mu\'id</item>
<item>Al-Muhyi</item>
<item>Al-Mumit</item>
<item>Al-Hayy</item>
<item>Al-Qayyum</item>
<item>Al-Wajid</item>
<item>Al-Majid</item>
<item>Al-Wahid</item>
<item>Al-Ahad</item>
<item>As-Samad</item>
<item>Al-Qadir</item>
<item>Al-Muqtadir</item>
<item>Al-Muqaddim</item>
<item>Al-Mu\'akhkhir</item>
<item>Al-Awwal</item>
<item>Al-Akhir</item>
<item>Az-Zahir</item>
<item>Al-Batin</item>
<item>Al-Wali</item>
<item>Al-Muta\'ali</item>
<item>Al-Barr</item>
<item>At-Tawwab</item>
<item>Al-Muntaqim</item>
<item>Al-\'Afuww</item>
<item>Ar-Ra\'uf</item>
<item>Malik-al-Mulk</item>
<item>Dhu-al-Jalal \n wa-al-Ikram</item>
<item>Al-Muqsit</item>
<item>Al-Jami\'</item>
<item>Al-Ghani</item>
<item>Al-Mughni</item>
<item>Al-Mani\'</item>
<item>Ad-Darr</item>
<item>An-Nafi\'</item>
<item>An-Nur</item>
<item>Al-Hadi</item>
<item>Al-Badi</item>
<item>Al-Baqi</item>
<item>Al-Warith</item>
<item>Ar-Rashid</item>
<item>As-Sabur</item>
</string-array>
<string-array name="names_arabic">
<item>الرحمن</item>
<item >الرحيم</item>
<item> الملك</item>
<item> القدوس</item>
<item>السلام</item>
<item>المؤمن</item>
<item >المهيمن</item>
<item >العزيز</item>
<item>الجبار</item>
<item >المتكبر</item>
<item >الخالق</item>
<item >البارئ</item>
<item >المصور</item>
<item >الغفار</item>
<item >القهار</item>
<item >الوهاب</item>
<item >الرزاق</item>
<item >الفتاح</item>
<item >العليم</item>
<item >القابض</item>
<item >الباسط</item>
<item >الخافض</item>
<item >الرافع</item>
<item >المعز</item>
<item >المذل</item>
<item >السميع</item>
<item >البصير</item>
<item >الحكم</item>
<item >العدل</item>
<item >اللطيف</item>
<item >الخبير</item>
<item >الحليم</item>
<item >العظيم</item>
<item >الغفور</item>
<item >الشكور</item>
<item >العلى</item>
<item >الكبير</item>
<item >الحفيظ</item>
<item >المقيت</item>
<item >الحسيب</item>
<item >الجليل</item>
<item >الكريم</item>
<item >الرقيب</item>
<item >المجيب</item>
<item >الواسع</item>
<item >الحكيم</item>
<item >الودود</item>
<item >المجيد</item>
<item >الباعث</item>
<item >الشهيد</item>
<item >الحق</item>
<item >الوكيل</item>
<item >القوى</item>
<item >المتين</item>
<item > الولى</item>
<item >الحميد</item>
<item >المحصى</item>
<item >المبدئ</item>
<item >المعيد</item>
<item >المحيى</item>
<item >المميت</item>
<item >الحي</item>
<item >القيوم</item>
<item >الواجد</item>
<item >الماجد</item>
<item >الواحد</item>
<item >الصمد</item>
<item >الاحد</item>
<item >القادر</item>
<item >المقتدر</item>
<item >المقدم</item>
<item >المؤخر</item>
<item >الأول</item>
<item >الأخر</item>
<item >الظاهر</item>
<item >الباطن</item>
<item >الوالي</item>
<item >المتعالي</item>
<item >البر</item>
<item >التواب</item>
<item >المنتقم</item>
<item >العفو</item>
<item >الرؤوف</item>
<item >مالك الملك</item>
<item >ذو الجلال و الإكرام</item>
<item >المقسط</item>
<item >الجامع</item>
<item >الغنى</item>
<item >المغنى</item>
<item > المانع</item>
<item > الضار</item>
<item >النافع</item>
<item > النور</item>
<item >الهادي</item>
<item >البديع</item>
<item >الباقي</item>
<item >الوارث</item>
<item > الرشيد</item>
<item > الصبور</item>
</string-array>
<string-array name="meaning">
<item >The All-Compassionate</item>
<item >The All-Merciful</item>
<item >The Absolute Ruler</item>
<item >The Pure One</item>
<item >The Source of Peace</item>
<item >The Inspirer of Faith</item>
<item >The Guardian</item>
<item >The Victorious</item>
<item >The Compeller</item>
<item >The Greatest</item>
<item >The Creator</item>
<item >The Maker of Order</item>
<item >The Shaper of Beauty</item>
<item >The Forgiving</item>
<item >The Subduer</item>
<item >The Giver of All</item>
<item >The Sustainer</item>
<item >The Opener</item>
<item >The Knower of All</item>
<item >The Constrictor</item>
<item >The Reliever</item>
<item >The Abaser</item>
<item >The Exalter</item>
<item >The Bestower of Honors</item>
<item >The Humiliator</item>
<item >The Hearer of All</item>
<item >The Seer of All</item>
<item >The Judge</item>
<item >The Just</item>
<item >The Subtle One</item>
<item >The All-Aware</item>
<item >The Forbearing</item>
<item >The Magnificent</item>
<item >The Forgiver and Hider of Faults</item>
<item >The Rewarder of Thankfulness</item>
<item >The Highest</item>
<item >The Greatest</item>
<item >The Preserver</item>
<item >The Nourisher</item>
<item >The Accounter</item>
<item >The Mighty</item>
<item >The Generous</item>
<item >The Watchful One</item>
<item >The Responder to Prayer</item>
<item >The All-Comprehending</item>
<item >The Perfectly Wise</item>
<item >The Loving One</item>
<item >The Majestic One</item>
<item >The Resurrector</item>
<item >The Witness</item>
<item >The Truth</item>
<item >The Trustee</item>
<item >The Possessor of All Strength</item>
<item >The Forceful One</item>
<item >The Governor</item>
<item >The Praised One</item>
<item >The Appraiser</item>
<item >The Originator</item>
<item >The Restorer</item>
<item >The Giver of Life</item>
<item >The Taker of Life</item>
<item >The Ever Living One</item>
<item >The Self-Existing One</item>
<item >The Finder</item>
<item >The Glorious</item>
<item >The Unique, The Single</item>
<item >The One, The Indivisible</item>
<item >The Satisfier of All Needs</item>
<item >The All Powerful</item>
<item >The Creator of All Power</item>
<item >The Expediter</item>
<item >The Delayer</item>
<item >The First</item>
<item >The Last</item>
<item >The Manifest One</item>
<item >The Hidden One</item>
<item >The Protecting Friend</item>
<item >The Supreme One</item>
<item >The Doer of Good</item>
<item >The Guide to Repentance</item>
<item >The Avenger</item>
<item >The Forgiver</item>
<item >The Clement</item>
<item >The Owner of All</item>
<item >The Lord of Majesty and Bounty</item>
<item >The Equitable One</item>
<item >The Gatherer</item>
<item >The Rich One</item>
<item >The Enricher</item>
<item >The Preventer of Harm</item>
<item >The Creator of The Harmful</item>
<item >The Creator of Good</item>
<item >The Light</item>
<item >The Guide</item>
<item >The Originator</item>
<item >The Everlasting One</item>
<item >The Inheritor of All</item>
<item >The Righteous Teacher</item>
<item >The Patient One </item>
</string-array>
<string-array name="music">
<item> rahman</item>
<item> rahim </item>
<item> malik </item>
<item> quddus </item>
<item> salam</item>
<item> mumin </item>
<item> muhaimin</item>
<item> aziz</item>
<item> jabbar</item>
<item> mutakabbir</item>
<item> khaliq</item>
<item> bari</item>
<item> musawwir</item>
<item> ghaffar</item>
<item> qahhar</item>
<item> wahhab</item>
<item> razzaq</item>
<item> fattah</item>
<item> alim </item>
<item> qabid </item>
<item> basit</item>
<item> khafid </item>
<item> rafi </item>
<item> muizz </item>
<item> mudhill </item>
<item> sami</item>
<item> basir</item>
<item> hakam</item>
<item> adl </item>
<item> latif</item>
<item> khabir</item>
<item> halim</item>
<item> azim</item>
<item> ghafur</item>
<item>shakur</item>
<item> ali</item>
<item> kabir</item>
<item>hafiz</item>
<item> muqit</item>
<item> hasib</item>
<item> jalil</item>
<item> karim</item>
<item> raqib</item>
<item> mujib</item>
<item> wasi</item>
<item> hakim</item>
<item> wadud</item>
<item> majeed</item>
<item> baith</item>
<item> shahid</item>
<item> haqq</item>
<item> wakil</item>
<item> qawi</item>
<item> matin</item>
<item> wali</item>
<item> hamid</item>
<item> muhsi</item>
<item> mubdi</item>
<item> muid</item>
<item> muhyi</item>
<item> mumit</item>
<item> hayy</item>
<item> qayyum</item>
<item> wajid</item>
<item> majeed</item>
<item> wahid</item>
<item> a</item>
<item> samad</item>
<item> qadir</item>
<item> muqtadir</item>
<item> muqaddim</item>
<item> muakhkhir2a</item>
<item> awwal</item>
<item> akhir</item>
<item> zahir</item>
<item> batin</item>
<item> wali</item>
<item> muta_ali</item>
<item> barr</item>
<item> tawwab</item>
<item> muntaqim</item>
<item> afuw</item>
<item> rauf</item>
<item> malik_ul_mulk</item>
<item> dhu_l_jalali_wal_ikram</item>
<item> muqsit</item>
<item> jami</item>
<item> ghaniy</item>
<item> mughni</item>
<item> mani</item>
<item> darr</item>
<item> nafi</item>
<item> nur</item>
<item> hadi</item>
<item> badi</item>
<item> baqi</item>
<item> warith</item>
<item>rashid</item>
<item>sabur</item>
</string-array>
Probably the problem is with your arrays, you need to debug to check. You can post your arrays.
Related
I'm currently using this style for my popup menu:
<style name="mainActivityTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="colorPrimary">#color/colorBlack</item>
<item name="colorPrimaryDark">#color/colorBlack</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
How ever it causes popup menus to have extra space on the top and bottom:
How do I make it so there is no extra space? Is there a certain style so that it wraps its contents?
Edit: I forgot to mention I inflate the view programmatically so that may be an issue
private void inflateMoreMenu(View view){
PopupMenu popupMenu = new PopupMenu(mContext, view);
popupMenu.inflate(R.menu.popup_menu);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
#Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()){
case R.id.popup_menu_report:
//Inflate a layout
break;
case R.id.popup_menu_block:
//Inflate a layout
break;
}
return false;
}
});
#SuppressLint("RestrictedApi")
MenuPopupHelper menuHelper = new MenuPopupHelper(mContext, (MenuBuilder) popupMenu.getMenu(), view);
menuHelper.setForceShowIcon(true);
menuHelper.show();
}
XML for popup_menu:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/popup_menu_report"
android:title="Report"
android:icon="#drawable/icon_messages_report"/>
<item
android:id="#+id/popup_menu_block"
android:title="Block"
android:icon="#drawable/icon_alertdialog_block"/>
</menu>
For the OverflowMenu you can define in your app theme the actionOverflowMenuStyle attribute.
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
<item name="actionOverflowMenuStyle">#style/popupOverflowMenu</item>
</style>
With:
<style name="popupOverflowMenu" parent="#style/Widget.MaterialComponents.PopupMenu.Overflow">
<item name="android:popupBackground">#drawable/my_mtrl_popupmenu_background</item>
</style>
The drawable/my_mtrl_popupmenu_background.xml file:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="?attr/colorSurface"/>
<corners
android:bottomLeftRadius="4dp"
android:bottomRightRadius="4dp"
android:topLeftRadius="4dp"
android:topRightRadius="4dp"/>
</shape>
It the original file there is the padding:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="?attr/colorSurface"/>
<corners
..../>
<padding
android:bottom="8dp"
android:top="8dp"/>
</shape>
For a popup you can use:
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
<item name="popupMenuStyle">#style/popupMenu</item>
</style>
<style name="popupMenu" parent="#style/Widget.MaterialComponents.PopupMenu">
<item name="android:popupBackground">#drawable/my_mtrl_popupmenu_background</item>
</style>
I have a list of items as follows: (act_pedido_drawer.xml)
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_inicio"
android:title="#string/nav_inicio"/>
</group>
<item
android:title="#string/nav_empresa"
android:id="#+id/nav_mi_empresa_title">
<menu>
<item
android:id="#+id/nav_mi_empresa"
android:title="#string/nav_mi_empresa"/>
<item
android:id="#+id/nav_inventario"
android:title="#string/nav_inventario"/>
<item
android:id="#+id/nav_descuentos"
android:title="#string/nav_descuentos"/>
<item
android:id="#+id/nav_clientes_proveedores"
android:title="#string/nav_clientes_proveedores"/>
<item
android:id="#+id/nav_ventas"
android:title="#string/nav_ventas"/>
<item
android:id="#+id/nav_reportes"
android:title="#string/nav_reportes"/>
<item
android:id="#+id/nav_suscribirse"
android:title="#string/nav_suscribirse"/>
</menu>
</item>
<item android:title="#string/nav_cuenta">
<menu>
<item
android:id="#+id/nav_gastos"
android:title="#string/nav_gastos"/>
<item
android:id="#+id/nav_impuestos"
android:title="#string/nav_impuestos"/>
<item
android:id="#+id/nav_hardware"
android:title="#string/nav_hardware"/>
<item
android:id="#+id/nav_terminos_condiciones"
android:title="#string/nav_terminos_condiciones"/>
<item
android:id="#+id/nav_cerrar_sesion"
android:title="#string/nav_cerrar_sesion"/>
</menu>
</item>
</menu>
Which has a similar appearance to the following image:
The list is invoked from the following xml file, (app:menu="#menu/act_pedido_drawer"):
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/act_bar_pedido"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_cabecera_act_pedido"
app:menu="#menu/act_pedido_drawer"/>
</android.support.v4.widget.DrawerLayout>
The way to determine which item has been selected is as follows:
#Override
public boolean onNavigationItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.nav_mi_empresa_title:{
break;
}
case R.id.nav_terminos_condiciones: {
break;
}
case R.id.nav_mi_empresa: {
break;
}
case R.id.nav_inventario: {
break;
}
case R.id.nav_descuentos: {
break;
}
case R.id.nav_clientes_proveedores: {
break;
}
case R.id.nav_ventas:{
break;
}
case R.id.nav_cerrar_sesion: {
break;
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
For all the items it works correctly, except for the item nav_mi_empresa_title which can be seen in the image that seems to be disabled.
My question is: Is there a way to enable it?
Thanks
Try this code, I simply put these two items inside menu:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_inicio"
android:title="#string/nav_inicio"/>
</group>
<item
android:title="#string/nav_empresa">
<menu>
<item
android:title="#string/nav_empresa"
android:id="#+id/nav_mi_empresa_title"/>
<item
android:id="#+id/nav_mi_empresa"
android:title="#string/nav_mi_empresa"/>
<item
android:id="#+id/nav_inventario"
android:title="#string/nav_inventario"/>
<item
android:id="#+id/nav_descuentos"
android:title="#string/nav_descuentos"/>
<item
android:id="#+id/nav_clientes_proveedores"
android:title="#string/nav_clientes_proveedores"/>
<item
android:id="#+id/nav_ventas"
android:title="#string/nav_ventas"/>
<item
android:id="#+id/nav_reportes"
android:title="#string/nav_reportes"/>
<item
android:id="#+id/nav_suscribirse"
android:title="#string/nav_suscribirse"/>
</menu>
</item>
<item android:title="#string/nav_cuenta">
<menu>
<item
android:id="#+id/nav_cuenta"
android:title="#string/nav_cuenta">
<item
android:id="#+id/nav_gastos"
android:title="#string/nav_gastos"/>
<item
android:id="#+id/nav_impuestos"
android:title="#string/nav_impuestos"/>
<item
android:id="#+id/nav_hardware"
android:title="#string/nav_hardware"/>
<item
android:id="#+id/nav_terminos_condiciones"
android:title="#string/nav_terminos_condiciones"/>
<item
android:id="#+id/nav_cerrar_sesion"
android:title="#string/nav_cerrar_sesion"/>
</menu>
</item>
</menu>
I will continue with the only idea suggested in this thread, but adding some lines of separation in some items.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<group android:id="#+id/grp1" android:checkableBehavior="single">
<item
android:id="#+id/nav_inicio"
android:title="#string/nav_inicio"/>
</group>
<group android:id="#+id/grp2" android:checkableBehavior="single">
<item
android:color="#color/colorDeshabilitado"
android:id="#+id/nav_mi_empresa_titulo"
android:title="#string/nav_empresa"/>
</group>
<group android:id="#+id/grp3" android:checkableBehavior="single">
<item
android:id="#+id/nav_mi_empresa"
android:title="#string/nav_mi_empresa"/>
<item
android:id="#+id/nav_inventario"
android:title="#string/nav_inventario"/>
<item
android:id="#+id/nav_descuentos"
android:title="#string/nav_descuentos"/>
<item
android:id="#+id/nav_clientes_proveedores"
android:title="#string/nav_clientes_proveedores"/>
<item
android:id="#+id/nav_ventas"
android:title="#string/nav_ventas"/>
<item
android:id="#+id/nav_reportes"
android:title="#string/nav_reportes"/>
<item
android:id="#+id/nav_suscribirse"
android:title="#string/nav_suscribirse"/>
</group>
<item
android:title="#string/nav_cuenta"
android:id="#+id/nav_titulo_cuenta">
<menu>
<item
android:id="#+id/nav_gastos"
android:title="#string/nav_gastos"/>
<item
android:id="#+id/nav_impuestos"
android:title="#string/nav_impuestos"/>
<item
android:id="#+id/nav_hardware"
android:title="#string/nav_hardware"/>
<item
android:id="#+id/nav_terminos_condiciones"
android:title="#string/nav_terminos_condiciones"/>
<item
android:id="#+id/nav_cerrar_sesion"
android:title="#string/nav_cerrar_sesion"/>
</menu>
</item>
</menu>
Thanks to #D.B. for answering.
Hi I have 1 activity with 3 buttons,I have now created the ability to change the theme app, and up here all okay but I do not know how to go from buttoshape.xml to buttoshape_blue.xml
This is my theme:
<resources>
<style name="AppTheme.Blue" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/primaryColor_blue</item>
<item name="colorPrimaryDark">#color/primaryColorDark_blue</item>
<item name="colorAccent">#color/primaryAccent_blue</item>
<item name="backgroundColor">#color/bianco</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.Red" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/primaryColor_red</item>
<item name="colorPrimaryDark">#color/primaryColorDark_red</item>
<item name="colorAccent">#color/primaryAccent_red</item>
<item name="backgroundColor">#color/bianco</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
this my button in xml
<Button
android:id="#+id/magic_item"
android:text="Magic Item"
android:textColor="#FFFFFF"
android:textSize="25dp"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#drawable/buttonshape"
android:shadowColor="#A8A8A8"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="5"
/>
and this is my buttonshape.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners
android:radius="14dp"
/>
<gradient
android:angle="45"
android:centerX="90%"
android:centerColor="#ec2127"
android:startColor="#CC1414"
android:endColor="#FFFFFF"
android:type="linear"
/>
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp"
/>
<size
android:width="270dp"
android:height="60dp"
/>
<stroke
android:width="3dp"
android:color="#FFFFFF"
/>
my Utility
public class Utility {
public static void setTheme(Context context, int theme) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
prefs.edit().putInt(context.getString(R.string.prefs_theme_key), theme).apply();
}
public static int getTheme(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
return prefs.getInt(context.getString(R.string.prefs_theme_key), -1);
}
}
and BaseActivity
public class BaseActivity extends AppCompatActivity {
private final static int THEME_BLUE = 1;
private final static int THEME_RED = 2;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
updateTheme();
}
public void updateTheme() {
if (Utility.getTheme(getApplicationContext()) <= THEME_BLUE) {
setTheme(R.style.AppTheme_Blue);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().setStatusBarColor(getResources().getColor(R.color.primaryColorDark_blue));
}
} else if (Utility.getTheme(getApplicationContext()) == THEME_RED) {
setTheme(R.style.AppTheme_Red);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().setStatusBarColor(getResources().getColor(R.color.primaryColorDark_red));
}
}
}
}
You could create a custom theme attribute which would contain a reference to the background to use and set it to #drawable/buttonshape for AppTheme.Red and to #drawable/buttonshape_blue for AppTheme.Blue.
E.g. in values you could have an attrs.xml file in which there would be:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="buttonBackground" format="reference" />
</resources>
and in your themes.xml:
<style name="AppTheme.Blue" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/primaryColor_blue</item>
<item name="colorPrimaryDark">#color/primaryColorDark_blue</item>
<item name="colorAccent">#color/primaryAccent_blue</item>
<item name="backgroundColor">#color/bianco</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="backgroundColor">#color/bianco</item>
<item name="buttonBackground">#drawable/buttonshape_blue</item>
</style>
<style name="AppTheme.Red" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/primaryColor_red</item>
<item name="colorPrimaryDark">#color/primaryColorDark_red</item>
<item name="colorAccent">#color/primaryAccent_red</item>
<item name="backgroundColor">#color/bianco</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="buttonBackground">#drawable/buttonshape</item>
</style>
Your button in the layout file would look like this:
<Button
android:id="#+id/magic_item"
...
android:background="?attr/buttonBackground"
...
/>
public class ListCategorieActivity extends Activity implements AdapterView.OnItemClickListener {
public static String RISULTATO = "RISULTATO";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_categorie);
ListView listview = (ListView) findViewById(R.id.listView1);
listview.setOnItemClickListener(ListCategorieActivity.this);
}
public void onItemClick(AdapterView<?> l, View v, int position, long id) {
Bundle bundle = new Bundle();
Intent mIntent = new Intent();
String[] some_array = getResources().getStringArray(R.array.sections);
bundle.putString(RISULTATO,some_array[position]);
mIntent.putExtras(bundle);
setResult(RESULT_OK, mIntent);
finish();
}
The Activity ListCategorieActivity show a clickable list of item. My task is eliminate (delete) the item from the listview when the item is clicked. How I can accomplish this task with this code?
activity_list_categorie.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.example.utente.myapplication.ListCategorieActivity">
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:entries="#array/sections" >
</ListView>
array.xml:
<resources>
<string-array name="sections">
<item >OG 1</item>
<item >OG 2</item>
<item >OG 3</item>
<item >OG 4</item>
<item >OG 5</item>
<item >OG 6</item>
<item >OG 7</item>
<item >OG 8</item>
<item >OG 9</item>
<item >OG 10</item>
<item >OG 11</item>
<item >OG 12</item>
<item >OG 13</item>
<item >OS 1</item>
<item >OS 2-A</item>
<item >OS 2-B</item>
<item >OS 3</item>
<item >OS 4</item>
<item >OS 5</item>
<item >OS 6</item>
<item >OS 7</item>
<item >OS 8</item>
<item >OS 9</item>
<item >OS 10</item>
<item >OS 11</item>
<item >OS 12-A</item>
<item >OS 12-B</item>
<item >OS 13</item>
<item >OS 14</item>
<item >OS 15</item>
<item >OS 16</item>
<item >OS 17</item>
<item >OS 18-A</item>
<item >OS 18-B</item>
<item >OS 19</item>
<item >OS 20-A</item>
<item >OS 20-B</item>
<item >OS 21</item>
<item >OS 22</item>
<item >OS 23</item>
<item >OS 24</item>
<item >OS 25</item>
<item >OS 26</item>
<item >OS 27</item>
<item >OS 28</item>
<item >OS 29</item>
<item >OS 30</item>
<item >OS 31</item>
<item >OS 32</item>
<item >OS 33</item>
<item >OS 34</item>
<item >OS 35</item>
</string-array>
I think I not using an adapter.It is correct?
Just add listview.getAdapter.remove(position); in the OnItemClick method. I suppose you are using an ArrayAdapter though.
EDIT
I'm afraid my explanation was pretty sloppy. The OnItemClick method has 4 arguments: AdapterView l is the ListView whose children are being observed and int position is the child position in the ListView; if (and only if) the list adapter is an ArrayAdapter object, the remove(Object item) method is available and can be used to delete a list item; in order to get the right Object, one must call
Object item = ((ArrayAdapter)l.getAdapter()).getItem(position);
to get the Object to delete; then, the ((ArrayAdapter)l.getAdapter()).remove(item); can be called to remove the selected object.
You can put string resource into Arraylist, and simply use myArray.remove(position) method to delete an element in the list view.
You have 2 options
Remove the item from the list using the remove() method of your ArrayAdapter.
Object toRemove = arrayAdapter.getItem([POSITION]);
arrayAdapter.remove(toRemove);
Or modify the ArrayList and call notifyDataSetChanged().
arrayList.remove([index]);
arrayAdapter.notifyDataSetChanged();
When my button disabled i need remove text shadow effect and when button enable I need add this effect again.
selector_btn.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#drawable/btn_disabled"
android:state_enabled="false" />
<item
android:drawable="#drawable/btn_pressed"
android:state_pressed="true" />
<item
android:drawable="#drawable/btn_default" />
styles.xml
<style name="TextShadow">
<item name="android:textColor">#ffffffff</item>
<item name="android:shadowColor">#0D67B9</item>
<item name="android:shadowRadius">2.0</item>
<item name="android:shadowDy">-2.0</item>
</style>
<style name="BigButton" parent="TextShadow">
<item name="android:background">#drawable/selector_btn</item>
</style>
You have make 2 defferent styles for enable and disable condition and apply it to textview when it disable or vise versa ...
<style name="TextShadow_disable">
<item name="android:textColor">#ffffffff</item>
<item name="android:shadowColor">#0D67B9</item>
<item name="android:shadowRadius">0</item>
<item name="android:shadowDy">0</item>
</style>
<style name="TextShadow_enable">
<item name="android:textColor">#ffffffff</item>
<item name="android:shadowColor">#0D67B9</item>
<item name="android:shadowRadius">2.0</item>
<item name="android:shadowDy">-2.0</item>
</style>
textstyle = (TextView) findViewById(R.id.mytext);
textstyle.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
getTextStyle();
}
});
write down this method to check enable disable;
public void getTextStyle() {
if(textstyle.isEnabled()){
textstyle.setTextAppearance(this, R.style.TextShadow_enable);
}
else{
textstyle.setTextAppearance(this, R.style.TextShadow_disable);
}
}