I do not see the items in the gridview android - android

I have a GridView in which I put a horizontal scroll. When it was all vertical scroll was working perfectly, now I have changed the type of gridview to make it horizontal but you no longer see the items in the gridview.
in xml:
<com.jess.ui.TwoWayGridView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/dashboard_grid_report"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#E8E8E8"
app:gravity="center"
app:horizontalSpacing="0dp"
app:scrollDirectionLandscape="horizontal"
app:scrollDirectionPortrait="horizontal"
app:stretchMode="none"
app:verticalSpacing="0dp" />
xml of item:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/item_prospect"
android:layout_width="200dp"
android:layout_height="200dp"
android:background="#00BFFF" >
<TextView
android:id="#+id/TxtName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:textColor="#android:color/black" />
</RelativeLayout>
In file java:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_dashboard,
container, false);
TwoWayGridView gridViewReport = (TwoWayGridView) rootView.findViewById(R.id.dashboard_grid_report);
GridClientAdapter customGridClientAdapter = new GridClientAdapter(getActivity().getApplicationContext(), R.layout.item_client, Costant.listReport);
gridViewReport.setAdapter(customGridClientAdapter);
//......
return rootView;
}
when it was a usual gridview and vertical scroll was everything worked, asesso no longer works. Who can explain it to me?

In xml remove
app:stretchMode="none"
it works

Related

Viewing an image on a Android Fragment

I am having trouble showing an image from the drawable folder on to a fragment.
When I try to show do it, it comes up with a java.lang.NullPointerException.
any help would be appreciated.
This is my code,
public class Fragment4 extends Fragment {
public Fragment4() {
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate (R.layout.fragment4, container, false);
ImageView image = (ImageView)rootView.findViewById(R.id.image);
image.setImageResource(R.drawable.image123);
return rootView;
}
}
XML file
<?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="match_parent" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Your ImageView has no id. Set it as follows,
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
It is because you didn't add id attribute to the image in xml
Try this:
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

Android: Listview TextView won't marquee until it's out of view

I've managed to create a listview where when if titles are too long the textview will marquee continuously, however when I scroll to the bottom of the listview the text will stop marqueing and will only start up again if it goes out of view and then comes back into view again.
The same problem occurs when I use a searchview to populate a list view whereby the row has to go out of view and then back into view before the text starts marqueing.
Here is the 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"
android:background="#ebebeb"
android:clickable="true">
<SearchView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/searchView"
android:iconifiedByDefault="false"
android:imeOptions="actionSearch"
android:actionViewClass="android.support.v7.widget.SearchView"
android:focusable="false"/>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/searchedRecipesLSTV"
android:layout_gravity="center_horizontal"
android:focusableInTouchMode="true"
android:focusable="true"/>
</LinearLayout>
Here is the Java:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View recipeLayout = inflater.inflate(R.layout.search_recipe, container, false);
sView = (SearchView) recipeLayout.findViewById(R.id.searchView);
searchRecipesLSTV = (ListView) recipeLayout.findViewById(R.id.searchedRecipesLSTV);
//sView.requestFocusFromTouch();
sView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
#Override
public boolean onQueryTextSubmit(String query) {
new getJSON().execute(query); //Parse JSON and populate listview.
sView.clearFocus();
searchRecipesLSTV.requestFocus();
return false;
}
#Override
public boolean onQueryTextChange(String newText) {
if (sView.getQuery().length() == 0) {
}
return false;
}
});
return recipeLayout;
}
Here is the Adapter getView TextView specific:
holder.recipeTitle.setText(recipeList.get(position).getRecipeTitle());
holder.recipeTitle.setSelected(true);
holder.recipeTitle.requestFocus();
Finally heres the xml for each row in the listview:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<ImageView
android:layout_width="135dp"
android:layout_height="120dp"
android:id="#+id/recipepic_search"
android:src="#drawable/lillie"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/recipeTitle_tv_search"
android:gravity="center_horizontal"
android:textSize="30sp"
android:layout_marginTop="0dp"
android:scrollHorizontally = "true"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"/>
</LinearLayout>
Any help is appreciated, I've tried searching for refreshing focus on listview, programatically scrolling to the bottom and then to the top etc. I'm out of ideas. Thanks!

add elements in fragment's view android

I'm new to Android, I have a fragment which have this XML code
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:orientation="vertical"
android:id="#+id/linearRoot"
>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cv"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/person_name"
android:layout_alignParentTop="true"
android:textSize="30sp"
android:text="bonjour"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/person_age"
android:layout_below="#+id/person_name"
android:text="ce test a réussi"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</ScrollView>
With this one, I want to add several CardView Dynamically.So, as a test, I'm trying to add a second CardView in the LinearLayout this way :
public class TopRatedFragment extends Fragment {
LinearLayout ll;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_top_rated, container, false);
ll = (LinearLayout)rootView.findViewById(R.id.linearRoot);
CardView cv = new CardView(getActivity().getApplicationContext());
ll.addView(cv);
return rootView;
}
}
but it does nothing at all. I'm wondering what is the right way to do this.
you have to add LayoutParams (width, height) in order to actually show your CardView
cv.setLayoutParams(new ViewGroup.LayoutParams(20,20));
for example with 20dp width and height

Find List View in fragment from Activity

in my application I use SherlockActionBar with tab navigation.
In the activity MyFragmentActivity that extend SherlockFragmentActivity I add 3 tab with the fragment
mTabsAdapter.addTab(
bar.newTab().setText(getString(R.string.filmtab)),
FragmentFilm.class, null);
mTabsAdapter.addTab(
bar.newTab()
.setText(getString(R.string.cinematab)),
FragmentCinema.class, null);
mTabsAdapter.addTab(
bar.newTab()
.setText(getString(R.string.dintornitab)),
FragmentPdi.class, null);
The FragmentPdi class have this code:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.tab_pdi_info, container, false);
return view;
}
and the layout is
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:id="#+id/list_places"
android:layout_width="wrap_content"
android:layout_height="fill_parent" >
</ListView>
</RelativeLayout>
In the MyFragmentActivity I want find the listview for populate it in this way:
final ListView elencoPlaces = (ListView)findViewById(R.id.list_places);
....
but I have NullPointerException!
Why??
In the other fragment (FragmentFilm and FragmentCinema) I have other view like textview without this
problem!!
Please help me!
Thank you.
P.S. Is this the correct way for populate dinamically the views in fragment, or I must populate the view in the fragment class?? If the second how I can pass varible from the activity to the fragment??
if all you have in the layout file is a listview, don't bother overriding oncreateview. the default layout will give you that much. then you can use the methods built into the ListFragment - like getListView() and setListAdapter().
Ok, but I dont undestand why I have another fragment the FragmentCinema where I have this xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:paddingTop="10dip" android:id="#+id/otherCinemas" android:layout_width="fill_parent" android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout android:orientation="horizontal" android:id="#+id/plotSeparatorOtherCin" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="#id/txtProgrammation">
<ImageView android:layout_gravity="center_vertical" android:background="#drawable/palm_divider_line" android:layout_width="20.0dip" android:layout_height="wrap_content" android:layout_marginRight="5.0dip" />
<TextView android:layout_gravity="center_vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="#string/altricinema" android:textStyle="bold" />
<ImageView android:id="#+id/showOtherCinemas"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_action_freccia_cinema"
/>
<ImageView android:layout_gravity="center_vertical" android:background="#drawable/palm_divider_line" android:layout_width="fill_parent" android:layout_height="wrap_content" />
</LinearLayout>
<ListView
android:id="#+id/listOtherCinemas"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_below="#id/plotSeparatorOtherCin"
android:visibility="gone" >
</ListView>
</RelativeLayout>
and this code of class:
public class FragmentCinema extends SherlockFragment
{
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.tab_cinema_info, container, false);
return view;
}
}
and when I use the findViewbyId
final ListView cinemasOther = (ListView)findViewById(R.id.listOtherCinemas);
it works! But in FragmentPdi dont work!!
If you want to use ListView in ListFragments, your ListView must have id android:id="#+id/android:list"!

Custom View using onCreateView in a DialogFragment

Been trying to figure this out for a while now:
I'm trying to create a custom dialog using the standard approach shown on the Dev site.
public class CustomDialog extends DialogFragment {
private OnDialogResultListener mOnDialogResultListener = null;
public void setOnDialogResultListener(OnDialogResultListener dialogResultListener) {
mOnDialogResultListener = dialogResultListener;
}
public static CustomDialog newInstance(OnDialogResultListener dialogResultListener) {
CustomDialog frag = new CustomDialog();
frag.setOnDialogResultListener(dialogResultListener);
return frag;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
getDialog().setTitle(getString(R.string.Dialog_CustomDialog_Title));
View v = inflater.inflate(R.layout.customdialog, container, false);
return v;
}
}
With the XML being:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="fill_parent" android:background="#color/white" android:layout_margin="0px" android:layout_width="fill_parent">
<EditText android:hint="#string/Dialog.CustomDialog.OldPassword" android:layout_marginBottom="#dimen/normalMargin" android:layout_height="wrap_content" android:inputType="textPassword" android:id="#+id/EditText02" android:layout_width="fill_parent"></EditText>
<EditText android:hint="#string/Dialog.CustomDialog.NewPassword" android:layout_height="wrap_content" android:inputType="textPassword" android:id="#+id/EditText01" android:layout_width="fill_parent"></EditText>
<EditText android:hint="#string/Dialog.CustomDialog.RetypePassword" android:layout_height="wrap_content" android:inputType="textPassword" android:id="#+id/editText1" android:layout_width="fill_parent">
<requestFocus></requestFocus>
</EditText>
<LinearLayout android:layout_height="wrap_content" android:id="#+id/linearLayout1" android:layout_width="fill_parent">
<Button android:layout_height="wrap_content" android:text="#string/save" android:layout_width="#dimen/normalButtonWidth" android:id="#+id/btn_Custom_save"></Button>
<Button android:layout_height="wrap_content" android:text="#string/cancel" android:layout_width="#dimen/normalButtonWidth" android:id="#+id/btn_Custom_cancel"></Button>
</LinearLayout>
</LinearLayout>
And after creating and showing the dialog, I'm left with:
The white background has been applied to emphasize the unexpected and unwanted behavior.
Any ideas? I've tried changing width/heights, using weights in a horizontal LinearLayout, setting width/height programatically - all to no avail.
I found this tricks:
getDialog().getWindow().setBackgroundDrawableResource(R.color.white);
Looks like better solution.
I did come up with a cheap fix, which I would rather not have to use.
Adding a 0px height, 2000dp (some huge number) width view anywhere in the layout causes it to fill the dialog frame.
With the DialogFragment the width and height are null. Create an extra sub view group with fill parent and it should work for you.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_height="fill_parent" android:background="#color/white" android:layout_margin="0px" android:layout_width="fill_parent">
.....
If you set attachToRoot = true during inflater.inflate it should show dialog correctly.
View v = inflater.inflate(R.layout.customdialog, container, true);
I used a relativeLayout as the root view in my case and it actually filled out the dialog windows.

Categories

Resources