having a trouble here with the sliding tabs. So I have completed the tutorial but when i had a ListView to my Pager it only shows on the bottom of the screen.
Here is my 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="match_parent"
android:orientation="vertical">
<com.example.ambidata.innovway.SlidingTabLayout
android:id="#+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
android:background="#android:color/white"/>
</LinearLayout>
And my XML from ListView:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/issue_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#color/list_divider"
android:dividerHeight="1dp"
android:listSelector="#drawable/list_row_selector"/>
</LinearLayout>
Fragment Code:
public class TabIssues extends Fragment {
private ListView mainListView ;
private CustomListAdapter_Issues listAdapter;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Bundle b = getArguments();
int user_id = b.getInt("user_id");
boolean all = b.getBoolean("all");
WSConnectionIssues runner = new WSConnectionIssues(user_id, all);
runner.execute();
while (runner.download == AsyncTask.Status.RUNNING)
{
try
{
Thread.sleep(1);
} catch (Exception ex)
{
ex.printStackTrace();
}
}
View view = inflater.inflate(R.layout.activity_issues, container, false);
// Find the ListView resource.
mainListView = (ListView) view.findViewById(R.id.issue_list);
registerForContextMenu(mainListView);
// Create ArrayAdapter using the planet list.
View convertView = inflater.inflate(R.layout.row_issues, null);
listAdapter = new CustomListAdapter_Issues(this, runner.listIssues, convertView);
// Set the ArrayAdapter as the ListView's adapter.
mainListView.setAdapter(listAdapter);
return view;
}
Im using the phone for debug...as you can see blank...then the first item of my listview and if you scroll the others are there!
Could you try the listview layout as:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/issue_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:divider="#color/list_divider"
android:dividerHeight="1dp"
android:listSelector="#drawable/list_row_selector"/>
</RelativeLayout>
Related
I have the activity_main.xml with one FrameLayout relative to a ListViewFragment. I want to show this fragment in this activity. But its not working the ListView is not appearing. Do you know where is the issue?
main activity xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fragment_list"
/>
</android.support.constraint.ConstraintLayout>
Main activity:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// here Im trying to add the fragment A to the activity but the listview is not appearing
getSupportFragmentManager().
beginTransaction().add(R.id.fragment_list,new ListViewFragment()).commit();
}
}
listview xml:
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
ListViewFragment:
public class ListViewFragment extends Fragment {
private ListView editor=null;
ArrayList<String> items = new ArrayList<>();
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View result=inflater.inflate(R.layout.fragment_list, container, false);
editor=(ListView) (result.findViewById(R.id.listView));
ArrayAdapter arrayAdapter = new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, items);
editor.setAdapter(arrayAdapter);
return result;
}
}
Add height and width to the framelayout.
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/fragment_list" />
Also your listView Fragment cannot have listview as parent layout.So wrap it with a layout like frame layout.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
Hi i'm trying to put a listview inside a listview inside a listview.
The only problem is only the first listview is showing all elements correctly.
Every listview after that only contains one element.
UPDATE:
Creating my own non-scrollable listview fixed the problem.
https://stackoverflow.com/a/24629341/3713144
Here is some code:
activity_anlagen_details.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/DrawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="7dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="#+id/tool_bar"
layout="#layout/tool_bar"></include>
<TextView
android:id="#+id/anlagenName_textview"
android:layout_width="0dp"
android:layout_height="60dp"
android:gravity="center|center_vertical"
android:padding="3dip"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceLarge" />
<View
android:layout_width="fill_parent"
android:layout_height="4dp"
android:background="#424242" />
<ListView
android:id="#+id/listChecklisten"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/RecyclerView"
android:layout_width="320dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:background="#ffffff"
android:scrollbars="vertical">
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.DrawerLayout>
anlagen_checklisten_listview.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="60dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/checkliste_name"
android:layout_gravity="center_horizontal"
android:gravity="center|center_vertical"/>
<ListView
android:id="#+id/listChecklistenPunkte"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
and so on...
What i'm trying to do now is setting an ArrayAdapter for all listviews:
AnlagenDetailsActivity:
...
long anlagenId = getIntent().getLongExtra("anlagen_id", 0);
Log.d(logger, "Details for Anlage: " + anlagenId);
LocalAnlagenAccessor accessor = new LocalAnlagenAccessor(this);
Anlage anlage = accessor.readAnlage(anlagenId);
TextView anlagenName = (TextView) findViewById(R.id.anlagenName_textview);
anlagenName.setText(anlage.getName());
ListView listView = (ListView) findViewById(R.id.listChecklisten);
AnlagenChecklistenAdapter adapter = new AnlagenChecklistenAdapter(this);
listView.setAdapter(adapter);
adapter.addAll(anlage.getChecklisten());
...
AnlagenChecklistenAdapter:
...
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View checklisteView = inflater.inflate(R.layout.anlagen_checklisten_listview, parent, false);
TextView checklisteName = (TextView) checklisteView.findViewById(R.id.checkliste_name);
checklisteName.setText(getItem(position).getArt());
ListView listView = (ListView) checklisteView.findViewById(R.id.listChecklistenPunkte);
AnlagenChecklistenPunktAdapter adapter = new AnlagenChecklistenPunktAdapter(checklisteView.getContext());
listView.setAdapter(adapter);
adapter.addAll(getItem(position).getChecklistenPunkte());
return checklisteView;
}
...
The same goes on for one more listview.
What am I doing wrong here?
I'm using this library for the fab implementation.
As you can see in this video, the fab position is changing when the fragment loads.
After debugging it, I found that the listview "setAdapter()" method causes the position change.
I don't have a clue why it's happening..
My layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:theme="#style/AppTheme.ActionBar" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="#id/toolbar">
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:id="#android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/sad_face"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/no_leagues" />
</LinearLayout>
</FrameLayout>
<com.melnykov.fab.FloatingActionButton
android:id="#+id/fab_new_league"
android:src="#drawable/ic_action_add"
app:fab_colorNormal="#color/orange"
app:fab_colorPressed="#color/redDark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignBottom="#id/toolbar"
android:layout_marginBottom="-28dp"
android:layout_marginRight="28dp"
android:elevation="8dp"/>
</RelativeLayout>
My fragment
public class LeagueListFragment extends MyFragment {
#InjectView(android.R.id.list) ListView mListView;
#InjectView(android.R.id.empty) LinearLayout mEmpty;
public static Fragment newInstance() {
return new LeagueListFragment();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_league_list, container, false);
ButterKnife.inject(this, view);
// Fetch league list and set up adapter
List<League> list = League.getAll();
mAdapter = new LeagueAdapter(getActivity(), list);
// Set up ListView
mListView.setEmptyView(mEmpty);
mListView.setDivider(new ColorDrawable(getResources().getColor(R.color.gray)));
mListView.setDividerHeight(2);
mListView.setAdapter(mAdapter);
mListView.setOnItemClickListener(this);
return view;
}
}
Margin changes in the runtime on pre-Lollipop because shadow mustn't be taken into account when margins are set.
Try to disable the shadow by :
fab:fab_shadow="false"
Fixing the issue is not expected for now.. (See makovkastar answer)
How to add button in footer below listview in layout with fragment.
I have code as below:
In fragment java.
ListView listview;
Button button;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.category, container, false);
View footerView = inflater.inflate(R.layout.footer_category, null);
listview = (ListView) view.findViewById(R.id.categoryNewsItemGrid);
listview.addFooterView(footerView);
loadmore = (Button) footerView.findViewById(R.id.loadMore);
loadmore.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
Log.d("Mylog","Button can click");
}
});
return view;
}
/res/layout/category.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/categoryNewsItemGrid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#C5C5C5"
android:dividerHeight="2px" />
</LinearLayout>
/res/layout/footer_category.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/footerCategory"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/loadMore"
android:layout_width="fill_parent"
android:text="Load More" />
</LinearLayout>
And i get error(Force Close), if i see in logcat, i get message error Android Runtime in line 74, line 74 is:
View footerView = inflater.inflate(R.layout.footer_category, null);
My question, i want to add button in footer, below listview. like as this screenshot.
thanks.
You missed layout_height in your /res/layout/footer_category.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/footerCategory"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/loadMore"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Load More" />
</LinearLayout>
I am using the masterdetailsflow template to build a custom detail layout. it doesn't seem to work well. The closest question asked before does not seem to be solving my problem at
ListView not showing up in fragment
I put a Log to do debug, it seems to pass the "Check1" but it does not displaying.
public class RouteItemDetailFragment extends Fragment {
...
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_routeitem_detail, container, false);
if (mItem != null) {
((TextView) rootView.findViewById(R.id.routeitem_detail)).setText(mItem.title);
Log.i("GPS", "onCreateView - RouteItemDetailFragment - check listadapter");
}
return rootView;
}
#Override
public void onViewCreated (View view, Bundle savedInstanceState){
ArrayList<String> listItems = new ArrayList<String>();
listItems.add("helo1");
listItems.add("helo2");
listItems.add("helo3");
listItems.add("helo4");
ArrayAdapter<String> adapter;
((TextView) view.findViewById(R.id.txt1)).setText("kkkkkk");
Log.i("Check1", "onCreateView - RouteItemDetailFragment - check listadapter");
adapter=new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1,
listItems);
adapter.notifyDataSetChanged();
ListView listAdapter = (ListView) view.findViewById(R.id.lv);
listAdapter.setAdapter(adapter);
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/twopanecontainer"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
style="?android:attr/textAppearanceLarge"
android:id="#+id/routeitem_detail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
tools:context=".RouteItemDetailFragment" />
<TextView
android:id="#+id/txt1"
style="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
/>
<ListView
android:id="#+id/lv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ListView>
</LinearLayout>
Your LinearLayout displays Views horizontally by default, so your second TextView and ListView are probably just being displayed off screen. Change the orientation to "vertical":
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/twopanecontainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >