I have a fragment that displays some items "images and buttons"
I want to scroll all the screen, not just the gridview, I made some search and used some codes but it is sold not working, so how can I do that.......
..................................................................................
...................................................................................
Here is the problem 4 sec
my codes
<ScrollView
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:background="#FFFFFF"
android:overScrollMode="never"
android:scrollbars="none"
tools:context=".Fragment.ImagesFragmentProject.HomeImagesFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF">
<!-- editor's chooses text -->
<TextView
android:id="#+id/choose_text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/scrollView_image"
android:paddingTop="20dp"
android:paddingRight="10dp"
android:paddingBottom="6dp"
android:text="إختيار المحررين"
android:textColor="#color/colorBlack"
android:textSize="18sp"
android:textStyle="bold" />
<GridView
android:id="#+id/gridview_image_choose"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_below="#id/choose_text2"
android:background="#fff"
android:columnWidth="100dp"
android:fastScrollEnabled="false"
android:gravity="center"
android:horizontalSpacing="0dp"
android:numColumns="auto_fit"
android:paddingTop="8dp"
android:scrollbars="none"
android:stretchMode="columnWidth"
android:verticalSpacing="0dp" />
</RelativeLayout>
Java class
public class HomeImagesFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
/* ArrayList for chooseImages */
final String[] chooseImages = {
"https://i1.wp.com/www.newphotodownload.info/wp-content/uploads/2018/12/%D8%A8%D9%88%D8%B3%D8%AA%D8%A7%D8%AA-%D8%AF%D9%8A%D9%86%D9%8A%D8%A9-61-1.jpg",
"https://quotess.cc/wp-content/uploads/2020/01/4688.jpg",
"https://whatt.cc/wp-content/uploads/2018/07/4443.jpg",
"https://i1.wp.com/www.newphotodownload.info/wp-content/uploads/2018/12/%D8%A8%D9%88%D8%B3%D8%AA%D8%A7%D8%AA-%D8%AF%D9%8A%D9%86%D9%8A%D8%A9-61-1.jpg",
"https://quotess.cc/wp-content/uploads/2020/01/4688.jpg",
"https://whatt.cc/wp-content/uploads/2018/07/4443.jpg",
"https://i1.wp.com/www.newphotodownload.info/wp-content/uploads/2018/12/%D8%A8%D9%88%D8%B3%D8%AA%D8%A7%D8%AA-%D8%AF%D9%8A%D9%86%D9%8A%D8%A9-61-1.jpg"
};
/* make new object and find the view "GridView" */
GridView gridview1 = rootView.findViewById(R.id.gridview_image_choose);
// display all the images from Array on it
gridview1.setAdapter(new PicassoImagesAdapter(getActivity(), chooseImages));
/* display the image when click on it */
// we made a class for this method called "PicassoDisplayImageAdapter"
gridview1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// get the image
String image = chooseImages[position];
Intent intent = new Intent(getActivity(), PicassoDisplayImageAdapter.class);
intent.putExtra("imageUrl", image);
getActivity().startActivity(intent);
}
});
return rootView;
}
}
Related
I have a nav fragment section called GroupbookFragment which uses a TabLayout with 3 Tabs.
(GroupbookKrippeFragment, GroupbookHafenFragment & GroupbookKindergartenFragment)
Each Tab has a CardView with a RecyclerView in it. The goal is to have a global "Add Child" Button on the GroupbookFragment level, which forward you to another activity with a form where you can create a new child. After filling data & clicking a save button, you'll come back to the GroupbookFragmentview and the new created data from the form will show up in the correct CardView within one of the three corresponding fragments.
So far I successfully implemented all functionalities when the methods and "Add child" button are already IN the corresponding tab child fragment (e.g. GroupbookKrippeFragment). The problem here is, whenever I change the tab from the tabLayout, the "Add Child" button is moving away aswell. So after moving all methods & the button into the parent fragment GroupbookFragment I can navigate through all pages and fill the form & save, but the recyclerView won't update and show the new created data in the child's recyclerView anymore?!
Thanks in advance for any help! Here is the code view:
GroupbookFragment.java
public class GroupbookFragment extends Fragment {
// initializing elements
RecyclerView recyclerView;
ChildListAdapter childListAdapter;
List<Child> children = new ArrayList<>();
RoomDb database;
FloatingActionButton addChildBtn;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_groupbook, container, false);
// inflate the layout for GB Krippe fragment
View viewKrippe = inflater.inflate(R.layout.fragment_groupbook_krippe, container, false);
// link recycler view to correct element
recyclerView = viewKrippe.findViewById(R.id.recycler_view_krippe);
// Tab layout initialization
TabLayout tabLayout = view.findViewById(R.id.tabLayout);
ViewPager2 viewPager = view.findViewById(R.id.viewPager_groupBook);
GroupbookAdapter adapterGroupBook = new GroupbookAdapter(getChildFragmentManager(), getLifecycle());
viewPager.setAdapter(adapterGroupBook);
// set 3 Tab titles
tabLayout.addTab(tabLayout.newTab().setText("Krippe"));
tabLayout.addTab(tabLayout.newTab().setText("Hafen"));
tabLayout.addTab(tabLayout.newTab().setText("Kindergarten"));
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
#Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
}
#Override
public void onTabUnselected(TabLayout.Tab tab) {
}
#Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
#Override
public void onPageSelected(int position) {
tabLayout.selectTab(tabLayout.getTabAt(position));
}
});
return view;
}
#Override
public void onViewCreated(#NonNull View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// add Child code
database = RoomDb.getInstance(getContext());
children = database.mainDAO().getAll();
updateRecycler(children);
// link var to app element & set on click route
addChildBtn = view.findViewById(R.id.child_add_btn);
addChildBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(GroupbookFragment.this.getContext(), AddChildActivity.class);
startActivityForResult(intent, 101);
}
});
}
#Override
public void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 101) {
if (resultCode == Activity.RESULT_OK) {
Child new_child = (Child) data.getSerializableExtra("child");
database.mainDAO().insert(new_child);
children.clear();
children.addAll(database.mainDAO().getAll());
childListAdapter.notifyDataSetChanged();
}
}
}
void updateRecycler(List<Child> children) {
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(GroupbookFragment.this.getContext()));
childListAdapter = new ChildListAdapter(GroupbookFragment.this.getContext(), children, childClickListener);
recyclerView.setAdapter(childListAdapter);
}
private final ChildClickListener childClickListener = new ChildClickListener() {
#Override
public void onClick(Child child) {
}
#Override
public void onLongClick(Child child, CardView cardView) {
}
};
}
GroupbookFragment.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
tools:context=".Fragments.HomeFragment">
<com.google.android.material.tabs.TabLayout
android:id="#+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:tabIndicatorAnimationMode="elastic" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="#id/tabLayout">
<androidx.viewpager2.widget.ViewPager2
android:id="#+id/viewPager_groupBook"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
<!-- Add floating button to add child-->
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/child_add_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_margin="#dimen/margin_cardView"
android:backgroundTint="#color/green"
android:src="#drawable/ic_add_child"
app:tint="#color/white" />
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
GroupbookKrippeFragment.xml
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Fragments.Groupbook.GroupbookKrippeFragment">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.cardview.widget.CardView
android:id="#+id/groupBook_krippe_1"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="#dimen/margin_cardView"
app:cardCornerRadius="#dimen/cornerRadius_Card"
app:cardElevation="#dimen/elevation_default"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="#id/groupBook_krippe_2"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/creme_500"
android:layout_weight="6"
android:padding="#dimen/padding_default">
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline_group_1_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.1" />
<ImageView
android:id="#+id/ic_groupBook_krippe_1"
android:layout_width="#dimen/iconSize_groupBook_header"
android:layout_height="match_parent"
android:scaleType="fitCenter"
android:src="#drawable/ic_groupbook_krippe_1_logo"
app:tint="#color/white"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="#id/guideline_group_1_start"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
/>
<TextView
android:id="#+id/title_groupBook_krippe_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/margin_default"
android:text="Gruppe 1"
android:textAllCaps="true"
android:textSize="#dimen/textSize_groupBook_title"
android:textColor="#color/white"
android:fontFamily="#font/candy_beans"
app:layout_constrainedWidth="true"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="#id/guideline_group_1_start"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="#id/desc_groupBook_krippe_1"/>
<TextView
android:id="#+id/desc_groupBook_krippe_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/margin_default"
android:text="Gesamt: 12 | Anwesend: 10"
android:textSize="#dimen/textSize_groupBook_subTitle"
android:textColor="#color/white"
android:fontFamily="#font/candy_beans"
app:layout_constrainedWidth="true"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="#id/guideline_group_1_start"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#id/title_groupBook_krippe_1"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="#dimen/padding_default"
android:orientation="vertical">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow>
<TextView
android:text="ID"
android:textStyle="bold"
android:gravity="center"
android:layout_weight="0.5"/>
<TextView
android:text="Vorname"
android:textStyle="bold"
android:gravity="center"
android:layout_weight="0.5"/>
<TextView
android:text="Nachname"
android:textStyle="bold"
android:gravity="center"
android:layout_weight="0.5"/>
<TextView
android:text="Geburtstag"
android:textStyle="bold"
android:gravity="center"
android:layout_weight="0.5"/>
<TextView
android:text="Geburtsort"
android:textStyle="bold"
android:gravity="center"
android:layout_weight="0.5"/>
<TextView
android:text="Konfession"
android:textStyle="bold"
android:gravity="center"
android:layout_weight="0.5"/>
<TextView
android:text="Nationalität"
android:textStyle="bold"
android:gravity="center"
android:layout_weight="0.5"/>
</TableRow>
</TableLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_view_krippe"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</androidx.recyclerview.widget.RecyclerView>
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
</RelativeLayout>
I Want to open a static HTML file in each click of List item but when i call my listview is disappeared . please help me to short out this problem.
My Tab1Fragment.java Code is this
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_tab1, container, false);
Resources res = getResources();
mainTopic = res.getStringArray(R.array.MainTopic);
mainDescription = res.getStringArray(R.array.DescriptionContent);
listView = (ListView) view.findViewById(R.id.listView);
MyAdapter myAdapter = new MyAdapter(getActivity(), mainTopic, image1,
mainDescription);
listView.setAdapter(myAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch (position) {
case 0:
wb=(WebView)view.findViewById(R.id.webView);
wb.loadUrl("file:///assets/ActivePassive.html");
wb.getSettings().setJavaScriptEnabled(true);
wb.setWebViewClient(new WebViewClient());
}
}
});
return view;
}
}
My fragment_tab1.xml code is :-
<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"
tools:context="androidthirst.company.abhi.totalenglish.Tab1Fragment">
<!-- TODO: Update blank fragment layout -->
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/listView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
And my separate listView code is this
single_row.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#1A237E"
android:gravity="center"
android:textStyle="bold"
android:textSize="30sp"
android:layout_margin="9dp"
android:textColor="#ffffff"
android:id="#+id/imageView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="#+id/textView"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/imageView"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="#+id/textView2"
android:layout_toRightOf="#+id/imageView"
android:layout_below="#+id/textView"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignBottom="#+id/imageView" />
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/webView">
</WebView>
</RelativeLayout>
Here you can see the image i just want to open thml file in first list Item Click
Try Bellow code:
list_Id.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
list_Id.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
WebView webView = new WebView(v.getContext());
String[] urls = getResources().getStringArray(R.array.bookmark_urls);
webView.loadUrl(urls[position]);
}
});
}
});
Create a file string-array.xml inside values and put all web addresses as bellow:
<resources>
<string-array name="bookmark_urls">
<item>http://www.google.com</item>
<item>http://www.android.com/</item>
<item>http://www.facebook.com/</item>
<item>http://www.android.com/</item>
<item>http://www.android.com/</item>
</string-array>
</resources>
you can use something like below
String url = "http://www.example.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
Your layout is "fragment_tab1"
View view = inflater.inflate(R.layout.fragment_tab1, container, false);
While you wrot layout name "My tab1_fragment.xml code is :-"
please check is that exact layout?
And your Webview is in Row file which used in adapter class.. (single_row.xml)
You tried to load in activity..
Thanks abhi..
When I add an item below the "ADD ITEM BELOW" comment as shown below, my onItemLongClick and ListItemClick cannot work. However once I've removed the items below the "ADD ITEM BELOW", it will work. What's wrong?
<?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:background="#color/caldroid_transparent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/event_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/event_list_margin"
android:layout_marginBottom="#dimen/event_list_margin"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="80dp"
android:layout_height="80dp"
android:orientation="vertical"
android:layout_marginLeft="#dimen/standard_margin_size">
<TextView
android:id="#+id/event_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="20"
android:gravity="center"
android:layout_centerHorizontal="true"
android:textColor="#color/caldroid_black"
android:textSize="45dp" />
<TextView
android:id="#+id/event_month_year"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="JAN 2015"
android:textSize="12dp"
android:gravity="center"
android:layout_below="#id/event_day"
android:textColor="#color/caldroid_black" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="#dimen/standard_padding_size"
android:paddingBottom="#dimen/standard_padding_size"
android:paddingLeft="#dimen/feed_item_profile_info_padd"
android:paddingRight="#dimen/feed_item_profile_info_padd"
android:layout_marginLeft="#dimen/feed_item_profile_info_padd"
android:layout_marginRight="#dimen/feed_item_profile_info_padd"
android:id="#+id/event_set_colour">
<TextView
android:id="#+id/event_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Title"
android:textStyle="bold"
android:textColor="#color/caldroid_black"
android:textSize="#dimen/standard_text_size" />
<TextView
android:id="#+id/event_location"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="local"
android:layout_below="#id/event_title"
android:textColor="#color/caldroid_black"
android:textSize="#dimen/feed_item_profile_name" />
<TextView
android:id="#+id/event_start_end_time"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/event_location"
android:text="28 May 2015, Saturday"
android:textColor="#color/caldroid_black"
android:textSize="#dimen/feed_item_profile_name" />
</RelativeLayout>
</LinearLayout>
<!-- ADD ITEM BELOW -->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"/>
</LinearLayout>
EventFragment.java
public class EventFragment extends ListFragment {
//Set database to allow user to retrieve data to populate EventFragment.java
private AppointmentController appointmentDatabase;
//List to get all the appointments
private List<Appointment> allAppointment;
EventAdapter adapter;
Appointment selected_appointment;
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Get all the appointment
appointmentDatabase = new AppointmentController(getActivity());
appointmentDatabase.open();
allAppointment = appointmentDatabase.getAllAppointment();
//Initialise ArrayAdapter adapter for view
adapter = new EventAdapter(getActivity(), R.layout.row_event, allAppointment);
setListAdapter(adapter);
getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
#Override
public boolean onItemLongClick(AdapterView<?> arg0, View view, int position, long id) {
// remove code for simplicity
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_listfragment, container, false);
return rootView;
}
#Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
// remove code for simplicity
}
If you wants to make onItemClick work add
android:descendantFocusability="blocksDescendants"
to the parent layout something like it:-
<?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:background="#color/caldroid_transparent"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants">
</LinearLayout>
when you blocksDescendants then you can not get onClick event on
Button in row of ListView. Basically you can get event on either row
or Button in a row.
Try changing:
#Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
// remove code for simplicity
}
to
getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public boolean onItemClick(AdapterView<?> arg0, View view, int position, long id) {
// whatever code would have been above put in here
}
For some reason the listview is not animating, only the textviews are. I have a feeling it has to do with the LayoutInflater but I am not sure. This is where I define the JazzyListView and its animation:
public class RssFragment extends Fragment implements AdapterView.OnItemClickListener {
private ProgressBar progressBar;
private View view;
private View view2;
private JazzyListView listView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (view == null) {
view = inflater.inflate(R.layout.fragment_layout,container, false);
progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
listView= (JazzyListView) view.findViewById(R.id.listView);
listView.setOnItemClickListener(this);
startService();
} else {
}
return view;
}
private void startService() {
Intent intent = new Intent(getActivity(), RssService.class);
intent.putExtra(RssService.RECEIVER, resultReceiver);
getActivity().startService(intent);
}
private final ResultReceiver resultReceiver = new ResultReceiver(new Handler()) {
#SuppressWarnings("unchecked")
#Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
List<RssItem> items = (List<RssItem>) resultData.getSerializable(RssService.ITEMS);
if (items != null) {
RssAdapter adapter = new RssAdapter(getActivity(), items);
listView.setAdapter(adapter);
} else {
Toast.makeText(getActivity(), "The RSS feed is unable to be downloaded at this time",
Toast.LENGTH_LONG).show();
}
progressBar.setVisibility(View.GONE);
listView.setTransitionEffect(JazzyHelper.GROW);
listView.setVisibility(View.VISIBLE);
};
};
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
RssAdapter adapter = (RssAdapter) parent.getAdapter();
RssItem item = (RssItem) adapter.getItem(position);
Intent intent = new Intent(Intent.ACTION_VIEW);
startActivity(intent);
}
}
Here is 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="wrap_content"
android:layout_height="fill_parent"
android:baselineAligned="false">
<ImageView
android:layout_width="fill_parent"
android:layout_height="50dp"
android:id="#+id/imageView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="#ff090eae" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="KGHS"
android:id="#+id/button"
android:layout_alignBottom="#+id/imageView"
android:layout_centerHorizontal="true" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageButton"
android:layout_alignBottom="#+id/imageView"
android:layout_alignParentRight="true"
/>
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
<com.twotoasters.jazzylistview.JazzyListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/listView"
android:divider="#b5b5b5"
app:effect= "grow"
android:dividerHeight="10dp"
android:layout_below="#+id/searchView"
android:layout_marginBottom="60dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView2"
android:layout_below="#id/imageView"
android:layout_centerHorizontal="true" />
<SearchView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/searchView"
android:layout_below="#+id/imageView"
/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="60dp"
android:id="#+id/imageView3"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#ffdedede" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="EVENTS"
android:id="#+id/button2"
android:layout_alignBottom="#+id/imageView3"
android:layout_toLeftOf="#+id/button3"
android:layout_toStartOf="#+id/button3"
android:layout_centerHorizontal="true"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="STAFF"
android:id="#+id/button3"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/button"
android:layout_toEndOf="#+id/button" />
</RelativeLayout>
As I mentioned before the textviews (the textviews are in a different xml by themselves) are animating but the actual listview is not. I already tried changing the fragment to an activity in order to rid the view/layout inflater. Not sure what else to try.
[edit 1] Is this Android SDK animation? This is an image from the JazzyListView library sample application... I was under the impression the jazzylistview animated the listview as well, otherwise what is the point???
Animation of JazzyListView animates its items but not itself. If you want to animate a JazzyListView, then you have to use animations provided by Android SDK, I am afraid.
To add an animation in ListView, you first need to define an
XML containing your animation. In my case I created a fade_in.xml.
You need to put this file in res->anim->fade_in.xml folder
/res/anim/fade_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="500" />
</set>
Then, I created a class derived from BaseAdapter so that I can override the getView
function and that is where you can insert the animation code.
#Override
public View getView(int i, View view, ViewGroup viewGroup)
{
View view = inflater.inflate(R.layout.task_item_large_one_line, null);
...
Animation animation = AnimationUtils.loadAnimation(mainActivity, R.anim.fade_in);
animation.setStartOffset(i*500);
view.startAnimation(animation);
return view;
}
This is my activity code:
#Override
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
String[] names = new String[] { "Investor Relations", "Social Sharing", "Rate this app", "About Rathbones",
"Disclaimer", "Security", "Credits"};
// Create an ArrayAdapter, that will actually make the Strings above
// appear in the ListView
this.setListAdapter(new ArrayAdapter<String>(this, R.layout.moremenulist,
R.id.label, names));
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
// Get the item that was clicked
Object o = this.getListAdapter().getItem(position);
String keyword = o.toString();
Toast.makeText(this, "You selected: " + keyword, Toast.LENGTH_LONG).show();
}
And here is the xml file for this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="#+id/LinearLayout1"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:layout_height="wrap_content" android:id="#+id/label"></TextView>
<LinearLayout android:id="#+id/linearLayout2" android:layout_width="wrap_content" android:orientation="vertical" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:layout_alignParentBottom="true">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageButton android:layout_width="wrap_content" android:id="#+id/imgbtn1" android:layout_alignParentLeft="true" android:layout_alignBottom="#+id/imgbtn3" android:layout_height="wrap_content" android:src="#drawable/topnews" android:visibility="visible"></ImageButton>
<ImageButton android:layout_width="wrap_content" android:layout_alignParentRight="true" android:id="#+id/imgbtn5" android:layout_alignBottom="#+id/imgbtn4" android:layout_height="wrap_content" android:src="#drawable/more"></ImageButton>
<ImageButton android:layout_width="wrap_content" android:id="#+id/imageButton1" android:layout_height="wrap_content" android:src="#drawable/contact_us" android:layout_alignParentTop="true" android:layout_toRightOf="#+id/imgbtn1"></ImageButton>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
Now, when the activity is loading it is appending the menu with each item in the list. I just want it to appear only in bottom not with each and every list item.
any suggestions?
Edit-1 :
I tried this but getting an error of nullpointer exception
View footerView =
((LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer, null, false);
ListView lv = new ListView(this);
lv.addFooterView(footerView);
What do you mean by menu? Do you mean your ImageButtons?
If that's the case then remove those create another layout for those ImageButtons and add them using ListView.addFooterView() instead.
You could create e.g. list_footer_layout.xml, which contains your ImageButtons. Then:
public void onCreate(Bundle bundle) {
...
ListView lv = getListView(); // If your activity is ListActivity
View foot = getLayoutInflater().inflate(R.layout.list_footer_layout, null);
lv.addFooterView(foot);
}