Fragment overlaying an Activity layout - android

I'm having problems working with fragments. The problem is: I have a layout in my activity with a ListView. When i select an item in this ListView, instantiates a fragment replacing the activity layout. My result is both fragment and activity contents are showing on screen, overlaying each other. What can I fix that (the fragment just replacing the activity content)? Here is the codes:
activityLayout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/activity"
android:orientation="vertical">
<FrameLayout android:id="#+id/fragment_to_replace"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible"
android:orientation="vertical"
android:layout_gravity="center" >
<TextView android:id="#+id/textView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="visible"
android:text="#string/textView_select_table"
android:textSize="30dp"/>
<ListView android:layout_marginTop="20dp"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:id="#+id/listView"
android:visibility="visible"
android:paddingTop="40dp" />
</FrameLayout>
</LinearLayout>
Activity.java
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
View view = findViewById(R.id.activity);
//Getting the ListView
ListView listView = (ListView) view.findViewById(R.id.listView);
listView.setTextFilterEnabled(true);
//Setting the adapter
listView.setAdapter(new Adapter(this));
listView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
//Creates a fragment
addFragment();
}
});
}
public void addFragment(){
MyFragment newFragment;
FragmentTransaction newFragmentTransaction = getSupportFragmentManager().beginTransaction();
newFragment = (MyFragment) getSupportFragmentManager()
.findFragmentById(R.id.fragment);
if (newFragment == null){
newFragment = new MyFragment(this, getSupportFragmentManager());
newFragmentTransaction.replace(R.id.fragment_to_replace,
new SelectDrinkFragment(this, getSupportFragmentManager()));
newFragmentTransaction.addToBackStack(null);
newFragmentTransaction.commit();
}
}
fragmentLayout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="visible"
android:text="#string/textView_two"
android:textSize="20dp"/>
<LinearLayout android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="visible"
android:text="#string/textView" />
<TextView android:id="#+id/textView_two"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="visible"/>
</LinearLayout>
<TextView
android:id="#+id/textView_three"
android:layout_marginTop="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="visible"
android:text="#string/textView_three"/>
<ListView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="#+id/listView_two"
android:visibility="visible"
android:paddingTop="40dp" />
</LinearLayout>
Fragment.java
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, Bundle saveInstanceState){
View view = inflater.inflate(R.layout.fragment, container, false);
final ListView listView = (ListView) view.findViewById(R.id.listView_two);
CharSequence [] list = getResources().getStringArray(R.array.array);
listView.setAdapter(new ListAdapter(getContext(), list));
return view;
}
ListAdapter.java
public class ListAdapter extends BaseAdapter{
private Context context;
private CharSequence[] drinkArraySize;
public ListAdapter(Context context, CharSequence[] array){
super();
this.context = context;
this.array= array;
}
#Override
public int getCount() {
return array.length;
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return 0;
}
public Context getContext(){
return context;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LinearLayout linearLayout = new LinearLayout(getContext());
RadioButton radioButton = new RadioButton(getContext());
radioButton.setText(array[position]);
linearLayout.addView(radioButton);
return linearLayout;
}
}

FragmentTransaction.replace() looks like it only replaces another fragment (and not just any View), so I'm pretty sure this is expected behavior (or at least, I know I've had this happen to me before). I suppose you have a few options:
I don't see in your code anything that would make the fragment's background opaque. You could try that first and see if it helps. If it does, that might be the simplest.
You could just set the other items' visibilities to View.GONE at the same time you perform your transaction, but that has some issues as far as backstack goes.
You could replace the ListView and TextView with a ListFragment instead. This is probably the "best" way to do it, but also is probably the most work.

Related

ListView onItemClickListener not working within fragment

I know there is a few dozens of these posts, however even after hours of searching and trying different solutions I have not been able to make my list view work.
The ListView is within a fragment, which also contaains a TextView, and is the reason it is not a ListFragment. This fragment is within an Activity that contains the Fragment as a Framelayout and a Button.
The ListView is getting populated with data, but clicking on one of these items nothing happens.
Activity
public class TurnOnHeadbandActivity extends AppCompatActivity {
private MuseManagerAndroid manager = null;
private final Handler handler = new Handler();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.turn_on_headband_activity);
// XX this must come before other libmuse API calls; it loads the
// library.
manager = MuseManagerAndroid.getInstance();
manager.setContext(this);
manager.startListening();
handler.post(tickUi);
}
private final Runnable tickUi = new Runnable() {
#Override
public void run() {
List<Muse> pairedMuses = manager.getMuses();
if (pairedMuses.size() >= 1) {
Fragment connectedFragment = new TurnOnHeadbandConnectedFragment();
PairedMuses pairedMusesObject = new PairedMuses(pairedMuses);
Bundle args = new Bundle();
args.putSerializable("pairedMuses", pairedMusesObject);
connectedFragment.setArguments(args);
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.turnOnFragment, connectedFragment);
fragmentTransaction.commit();
}
handler.postDelayed(tickUi, 1000 / 60);
}
};
}
XML for Activity
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/nightsky">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="2">
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:id="#+id/turnOnFragment"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3">
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#drawable/faqbutton"
android:layout_margin="10dp"
android:textColor="#color/textColor"
android:text="FAQ"/>
</LinearLayout>
Fragment
public class TurnOnHeadbandConnectedFragment extends Fragment implements OnItemClickListener {
private ListView museListView;
public TurnOnHeadbandConnectedFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.turn_on_headband_connected_fragment, container, false);
Bundle bundle = getArguments();
PairedMuses pairedMuses = (PairedMuses)bundle.getSerializable("pairedMuses");
// Fetch the names and MacAddresses of connected muses and store them in string array
int musesAmount = pairedMuses.getPairedMuses().size();
String[] musesMacAddresses = new String[musesAmount];
for (int i = 0; i < musesAmount; i++) {
musesMacAddresses[i] = String.valueOf(pairedMuses.getPairedMuses().get(i).getName().concat(pairedMuses.getPairedMuses().get(i).getMacAddress()));
}
museListView = (ListView) rootView.findViewById(R.id.museListView);
ArrayAdapter<String> listViewAdapter = new ArrayAdapter<>(getActivity(), R.layout.listview_item, musesMacAddresses);
museListView.setAdapter(listViewAdapter);
museListView.setOnItemClickListener(this);
return rootView;
}
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(getActivity(), Activity.class);
intent.putExtra("id", id);
startActivity(intent);
}
}
XML for Fragment
<LinearLayout 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:orientation="vertical"
android:layout_margin="10dp"
tools:context="com.musesleep.musesleep.TurnOnHeadbandConnectedFragment"
android:descendantFocusability="blocksDescendants">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:gravity="center"
android:textColor="#color/textColor"
android:text="Select your headband from the list:"/>
<ListView
android:id="#+id/museListView"
android:layout_marginTop="5dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="false"
android:focusableInTouchMode="false"/>
</LinearLayout>
XML for custom ListView Item
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="40dp"
android:padding="5dp"
android:background="#40D3D3D3"
android:gravity="center_vertical"
android:textColor="#color/textColor"/>

How give number to listview items in android

I am new to android . I have an application working with listview and i want to number each list view item.
Like,
1 list item
2 list item
3 list item
MainActivity.java
public class MainActivity extends AppCompatActivity {
private OrderDbManager orderDbManager;
private ListView listView;
private SimpleCursorAdapter adapter;
final String[] from = new String[] { OrderDbHelper.FOOD_NAME,
OrderDbHelper.QUANTITY, OrderDbHelper.PRICE };
final int[] to = new int[] {R.id.tvFoodName, R.id.tvItemQuantity, R.id.tvItemPrice };
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
orderDbManager = new OrderDbManager(this);
orderDbManager.open();
final Cursor cursor = orderDbManager.fetch();
listView = (ListView) findViewById(R.id.listView);
listView.setEmptyView(findViewById(R.id.empty));
adapter = new SimpleCursorAdapter(this, R.layout.list_item, cursor, from, to, 0);
adapter.notifyDataSetChanged();
LayoutInflater layoutInflater = getLayoutInflater();
listView.addHeaderView(layoutInflater.inflate(R.layout.cart_header,listView, false));
listView.setAdapter(adapter);
}
public class MyAdapter extends SimpleCursorAdapter {
public MyAdapter(Context context, int layout, Cursor c,
String[] from,int[] to) {
super(context, layout, c, from, to);
}
#Override
public int getCount() {
return 0;
}
#Override
public Object getItem(int arg0) {
return null;
}
#Override
public long getItemId(int arg0) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater layoutInflater =(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.list_item, null, true);
TextView txt= (TextView) convertView.findViewById(R.id.tvSlNo);
txt.setText(position + 1);
return convertView;
}
}
}
activity_main.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" >
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</ListView>
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:minHeight="50dp"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:id="#+id/tvSlNo"
android:layout_width="0dip"
android:layout_height="match_parent"
android:gravity="center"
android:textStyle="normal"
android:textColor="#android:color/black"
android:layout_weight="0.1" />
<TextView
android:id="#+id/tvFoodName"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:gravity="center"
android:textStyle="normal"
android:textColor="#android:color/black"
android:text=""/>
<TextView
android:id="#+id/tvItemQuantity"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="0.15"
android:textStyle="normal"
android:textColor="#android:color/black"
android:gravity="center"/>
<TextView
android:id="#+id/tvItemPrice"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:gravity="center"
android:textStyle="normal"
android:textColor="#android:color/black"
android:text=""/>
</LinearLayout>
i want to set numbering in tvSlNo.
please help
In your getView() method of your listViewAdapter simply use the position variable and set it on your TextView. You may need to add 1 to the position since it starts with 0. So use (position+1) and then set it to your TextView
Though this question may be too late but for other reference purposes.
Check where you have this code: txt.setText(position + 1);
you are close to your solution. You just have to typecast position + 1 to String since setText() only take String alone.

Android ListView requires two fingers to scroll

I have a rather simple layout that I am intending on using for basic chat in a fragment, but scrolling through the ListView requires me to place one finger on the screen on an item in the ListView and then scroll up or down with another finger. I was under the impression that a ListView should only require a single finger/touch to be able to scroll. Is there something I am overlooking in my layout, adapter or even potentially the code I am using to populate the adapter with?
Chat Layout XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF" >
<ListView
android:id="#+id/msgListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/form"
android:divider="#null"
android:dividerHeight="0dp"
android:scrollbarSize="3dp"
android:scrollbarStyle="outsideOverlay"
android:scrollbars="vertical"
android:scrollingCache="true"
android:smoothScrollbar="true"
android:paddingBottom="10dp" />
<LinearLayout
android:id="#+id/form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#color/primary"
android:orientation="horizontal"
android:paddingBottom="2dp" >
<EditText
android:id="#+id/messageEditText"
android:layout_width="252dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/button1"
android:layout_toLeftOf="#+id/sendMessageButton"
android:layout_weight="0.72"
android:ems="10"
android:maxHeight="80dp" />
<ImageButton
android:id="#+id/sendMessageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="#drawable/chat_send_button" />
</LinearLayout>
</RelativeLayout>
ListView Adapter
public class ChatMessageAdapter extends BaseAdapter {
private static LayoutInflater inflater = null;
ArrayList<ChatMessage> chatMessageList;
public ChatMessageAdapter(Activity activity, ArrayList<ChatMessage> list) {
chatMessageList = list;
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public int getCount() {
return chatMessageList.size();
}
#Override
public Object getItem(int position) {
return position;
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ChatMessage message = chatMessageList.get(position);
View vi = convertView;
if (convertView == null)
vi = inflater.inflate(R.layout.chat_bubble, null);
TextView msg = (TextView) vi.findViewById(R.id.message_text);
msg.setText(message.body);
TextView dateTime = (TextView) vi.findViewById(R.id.msgDateTime);
dateTime.setText(message.dateTime);
LinearLayout layout = (LinearLayout) vi
.findViewById(R.id.bubble_layout);
LinearLayout parent_layout = (LinearLayout) vi
.findViewById(R.id.bubble_layout_parent);
// if message is mine then align to right
if (message.isMine) {
layout.setBackgroundResource(R.drawable.bubble2);
parent_layout.setGravity(Gravity.RIGHT);
}
// If not mine then align to left
else {
layout.setBackgroundResource(R.drawable.bubble1);
parent_layout.setGravity(Gravity.LEFT);
}
msg.setTextColor(Color.BLACK);
return vi;
}
public void add(ChatMessage object) {
chatMessageList.add(object);
}
}
I had the same problem!
If you're using the navigation drawer, in the app_bar_main.xml change the CoordinatorLayout for the NestedScrollView
and then in your fragment in the scrollView set android:nestedScrollingEnabled="true"

fragment does not start at top

My application has a couple tabs of fragments with a viewpager and it does not start on top and I do not know why. Even when I scroll the fragment to the top, refreshing(going back and forth tabs) resets the fragment's start position right above the recyclerview.
fragment2.xml
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:isScrollContainer="false"
android:layout_gravity="fill_vertical"
android:clipToPadding="false"
android:fillViewport="true"
android:scrollbars="none"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="79dp"
android:scaleType="fitXY"
android:src="#drawable/sub4_visual"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="79dp"
android:alpha="0.3"
android:background="#000000"/>
</RelativeLayout>
<TextView
android:id="#+id/frag2_desc"
android:layout_margin="11dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textColor="#color/color_333333"
android:text=""/>
<Spinner
android:id="#+id/frag2_dropbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:overScrollMode="ifContentScrolls"
android:scrollbars="none"
android:gravity="left"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_subfrag2"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
Fragment2.java
public class Fragment2 extends Fragment{
...
public static Frag_BoardContent[] fragsList;
public static RecyclerView mRecyclerView;
public static Frag234_Adapter4 board_adapter;
public Fragment2() {
// Required empty public constructor
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
final View v = inflater.inflate(R.layout.fragment2, container, false);
tv_frag2Desc = (TextView) v.findViewById(R.id.frag2_desc);
spinner = (Spinner) v.findViewById(R.id.frag2_dropbox);
ArrayList<String> categoryList = new ArrayList<>();
if (connect) makeDynamicArray(categoryList);
adapter = new ArrayAdapter<> (getActivity(), R.layout.activity_board_spinner,categoryList);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(final AdapterView<?> parent, final View view, int position, long id) {
mRecyclerView.setLayoutManager(new LinearLayoutManager(MainActivity.context));
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setNestedScrollingEnabled(false);
board_adapter = new Frag234_Adapter4(MainActivity.context, fragsList);
mRecyclerView.setAdapter(board_adapter);
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
mRecyclerView = (RecyclerView) v.findViewById(R.id.recycler_subfrag2);
mRecyclerView.setAdapter(board_adapter);
return v;
}
public ArrayList<String> makeDynamicArray(){...}
}
It is a problem about focus. you need to do requestFocus() to your scrollview and
setFocusable(false)
to fragment;

ListView is not displayed in fragment

I implemented my own navigation drawer that comes from the left screen in my android application. The problem is that the ListView it is not visible and I can't figure out why.
This is the method onCreateView of the fragment where the list is (first I initialize the header of the layout and then the list with my custom adapter):
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View firstAccessView = inflater.inflate(R.layout.fragment_navigation_drawer, null);
this.profileImageDrawer = (ImageView) firstAccessView.findViewById(R.id.imageViewProfileDrawer);
RoundImage roundedImage = new RoundImage(BitmapFactory.decodeResource(getResources(), R.mipmap.iconuseranonymous));
//this.profileImageDrawer.setImageDrawable(roundedImage);
Picasso.with((Activity) getActivity()).load("https://graph.facebook.com/" + Profile.getCurrentProfile().getId() + "/picture?height=105&width=105")
.placeholder(roundedImage)
.transform(new CircleTransform()).fit().centerCrop().into(this.profileImageDrawer);
this.nameSurnameDrawer = (TextView) firstAccessView.findViewById(R.id.textViewDrawner);
this.nameSurnameDrawer.setText(Profile.getCurrentProfile().getFirstName() + " " + Profile.getCurrentProfile().getLastName());
List<String> example = new ArrayList<String>();
example.add("Profile");
example.add("Ask");
example.add("Logout");
this.adapter = new DrawerAdapter(getActivity(), example);
list = (ListView) firstAccessView.findViewById(R.id.listDrawer);
list.setAdapter(adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
selectItem(position);
}
});
list.setItemChecked(mCurrentSelectedPosition,true);
return firstAccessView;
}
This is the code of my custom adapter
private Activity context;
private List<String> list;
private View view;
private TextView textView;
public DrawerAdapter(Activity context, List<String> list) {
super(context, R.layout.drawerlist_layout);
this.context=context;
this.list = list;
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
view = inflater.inflate(R.layout.drawerlist_layout, null);
textView = (TextView) view.findViewById(R.id.sectionDrawer);
textView.setText(this.list.get(position));
textView.setTextColor(Color.BLACK);
return view;
}
and finally this is the layout of my fragment: at the top I have an header with an image and a TextView and then I have my custom ListView
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_weight="0.40"
android:background="#ffb200">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:id="#+id/imageViewProfileDrawer"
android:layout_gravity="left|center_vertical"
android:layout_marginLeft="20px" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Medium Text"
android:id="#+id/textViewDrawner"
android:layout_gravity="right|bottom"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:textColor="#ffffff"
android:textStyle="bold"
android:textIsSelectable="true" />
</FrameLayout>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="262dp" android:choiceMode="singleChoice"
android:divider="#cecece" android:dividerHeight="1dp"
android:background="#FFFFFF"
tools:context="com.bellantoni.chetta.lieme.NavigationDrawerFragment"
android:id="#+id/listDrawer"
android:drawSelectorOnTop="false"
android:smoothScrollbar="true"
android:longClickable="false"
android:nestedScrollingEnabled="false"
android:footerDividersEnabled="false"
android:headerDividersEnabled="true"
android:paddingLeft="10dp"
android:stackFromBottom="false"
android:scrollingCache="false"
android:paddingRight="10dp"
android:textFilterEnabled="false"
android:theme="#style/Base.Widget.AppCompat.ActionMode"
android:textAlignment="center"
android:transitionGroup="true"
android:layout_weight="0.60" />
I found my error in this line of code:
super(context, R.layout.drawerlist_layout);
where I missed the third parameter which in this case is list so it should be
super(context, R.layout.drawerlist_layout,list);
Set both FameLayout and ListView layout_width to 0dp instead of match_parent if you want to use layout_weight.

Categories

Resources