• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Android application Development

It depends on the requirement and situation. Fragments are normally used in cases where a page needs to change its content, or part of the screen needs to change dynamically. The tabbed view is a classic example of this - when you swipe the tabs, the screen content changes.

Activities are the natural choice where the user needs to navigate to other screens involving the input of data, or a new function of the app is invoked. But it really depends on the context, and you need to design a workflow through the app.
 
How can I use firebase, There are guidelines to use that but still I have some confusions while using this like i don't know some of the methods which are used in that please help me that how can i properly understand the firebase and implement that?
 
how can i retrieve the data from any web and display it in a customize manner. I can use WebView but it shows the data same as web and i want to customize it so what's the way to do it?
 
how can i retrieve the data from any web and display it in a customize manner. I can use WebView but it shows the data same as web and i want to customize it so what's the way to do it?

You should always use webview to show website page in app.
in-case you want to parse the content you can go for Java HTML Parser(jsoup)
using this library you can parse and access DOM elements to customize accordingly.but in my opinion parsing web page is not good idea.
 
How can I apply itemclicklistener on a gridview in the fragment? It does not respond to my code which is normally used. It is not print the log also and no errors are there.
Here is my code:
grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Log.e("<<<<","Click");
Toast.makeText(getActivity(),"hello",Toast.LENGTH_LONG).show();
}
});
Please help me to solve this issue and thanks for previous answers
 
How can I apply itemclicklistener on a gridview in the fragment? It does not respond to my code which is normally used. It is not print the log also and no errors are there.
Here is my code:
grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Log.e("<<<<","Click");
Toast.makeText(getActivity(),"hello",Toast.LENGTH_LONG).show();
}
});
Please help me to solve this issue and thanks for previous answers
Please post Getview method from your adapter class.
 
Try putting null in place of false at where you inflate your view.
As follows

convertView = layoutinflater.inflate(R.layout.example, parent, null);
 
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

View view=inflater.inflate(R.layout.fragment_fraghome,null);
pics_array=new ArrayList<>();
pics_array.add(R.drawable.squiiz);
pics_array.add(R.drawable.sblog);
pics_array.add(R.drawable.sgallery);
pics_array.add(R.drawable.scourses);
pics_array.add(R.drawable.sonline);
pics_array.add(R.drawable.sportfolio);
pics_array.add(R.drawable.sfaculty);
pics_array.add(R.drawable.stestimonial);
pics_array.add(R.drawable.sfaq);
pics_array.add(R.drawable.sstudentlife);
pics_array.add(R.drawable.sabout);
pics_array.add(R.drawable.svideos);

text_array=new ArrayList<>();
text_array.add("Quizzes");
text_array.add("Blogs");
text_array.add("Gallery");
text_array.add("Courses");
text_array.add("Online Courses");
text_array.add("Portfolio");
text_array.add("Faculties");
text_array.add("Testimonial");
text_array.add("FAQs");
text_array.add("Student's Life");
text_array.add("About us");
text_array.add("Video");

grid=view.findViewById(R.id.grid);
GridAdapter adapter =new GridAdapter(getActivity(),pics_array,text_array);
grid.setAdapter(adapter);
Toast.makeText(getActivity(),"hello",Toast.LENGTH_LONG).show();
Log.e("<<<<","Click outside");
grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
// String id=adapterView.getItemAtPosition(i).toString();
String id= String.valueOf(adapterView.getSelectedItemId());
Log.e("<<<<","Click");
Toast.makeText(getActivity(),id+"hello",Toast.LENGTH_LONG).show();
}
});
return view;
}
This is the code which is i am trying
 
R.layout.fragment_fraghome,null
I use the above line to check that the listener is applied or not
It was R.layout.fragment_fraghome,container,false before reading your post
and I was trying to replace false by null but it shows red line means the error in this.
Tell me another way to solve this issue I will be very thankful to you
 
The line
Java:
View view=inflater.inflate(R.layout.fragment_fraghome,null);
is not about listener, it's just the way to get root view for given fragment.
You should build root view like this:
Java:
View view=inflater.inflate(R.layout.fragment_fraghome, container, false);

What listener you are talking about. What do you want to get in your code.
 
I have a fragment and a gridview in that and wants to apply on itemclick listener but it doesn't work here is my code.

public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

View view=inflater.inflate(R.layout.fragment_fraghome, container,false);
pics_array=new ArrayList&lt;&gt;();
pics_array.add(R.drawable.squiiz);
pics_array.add(R.drawable.sblog);
pics_array.add(R.drawable.sgallery);
pics_array.add(R.drawable.scourses);
pics_array.add(R.drawable.sonline);
pics_array.add(R.drawable.sportfolio);
pics_array.add(R.drawable.sfaculty);
pics_array.add(R.drawable.stestimonial);
pics_array.add(R.drawabR.drawable.svideosle.sfaq);
pics_array.add(R.drawable.sstudentlife);
pics_array.add(R.drawable.sabout);
pics_array.add(R.drawable.svideos);

text_array=new ArrayList&lt;&gt;();
text_array.add('Quizzes');
text_array.add('Blogs');
text_array.add('Gallery');
text_array.add('Online');
text_array.add('Online Courses');
text_array.add('Portfolio');
text_array.add('Faculties');
text_array.add('Testimonial');
text_array.add('FAQs');
text_array.add('Student's Life');
text_array.add('About us');
text_array.add('Video');

grid=view.findViewById(R.id.grid);
GridAdapter adapter =new GridAdapter(getActivity(),pics_array,text_array);
grid.setAdapter(adapter);
Toast.makeText(getActivity(),'hello',Toast.LENGTH_LONG).show();
Log.e('&lt;&lt;&lt;&lt;','Click outside');
grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
<a href='https://androidforums.com/members/1021285/'>@override</a>
public void onItemClick(AdapterView adapterView, View view, int i, long l) {
// String id=adapterView.getItemAtPosition(i).toString();
String id= String.valueOf(adapterView.getSelectedItemId());
Log.e('&lt;&lt;&lt;&lt;','Click');
Toast.makeText(getActivity(),id+'hello',Toast.LENGTH_LONG).show();
}
});
return view;
}
 
Please format your code with <java code> </code> brackets
To answer on your question it's necessary to look at fragment_fraghome and GridAdapter implementation.
Because to check your code, I need to run project with your implementation, not mine.
 
Fragment where I want to apply itemclick listener on Gridview.
Fraghome.java
Code:
public class Fraghome extends Fragment {
    ArrayList<Integer>pics_array;
    ArrayList<String>text_array;
    GridView grid;
    Context context;


    public Fraghome() {
        // Required empty public constructor
    }

    [USER=1021285]@override[/USER]
    public void onAttach(Context context) {
        super.onAttach(context);
        this.context=context;
    }

    [USER=1021285]@override[/USER]
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View view=inflater.inflate(R.layout.fragment_fraghome,container,false);
        pics_array=new ArrayList<>();
        pics_array.add(R.drawable.squiiz);
        pics_array.add(R.drawable.sblog);
        pics_array.add(R.drawable.sgallery);
        pics_array.add(R.drawable.scourses);
        pics_array.add(R.drawable.sonline);
        pics_array.add(R.drawable.sportfolio);
        pics_array.add(R.drawable.sfaculty);
        pics_array.add(R.drawable.stestimonial);
        pics_array.add(R.drawable.sfaq);
        pics_array.add(R.drawable.sstudentlife);
        pics_array.add(R.drawable.sabout);
        pics_array.add(R.drawable.svideos);

        text_array=new ArrayList<>();
        text_array.add("Quizzes");
        text_array.add("Blogs");
        text_array.add("Gallery");
        text_array.add("Courses");
        text_array.add("Online Courses");
        text_array.add("Portfolio");
        text_array.add("Faculties");
        text_array.add("Testimonial");
        text_array.add("FAQs");
        text_array.add("Student's Life");
        text_array.add("About us");
        text_array.add("Video");

        grid=view.findViewById(R.id.grid);
       GridAdapter adapter =new GridAdapter(getActivity(),pics_array,text_array);
        grid.setAdapter(adapter);
        Toast.makeText(getActivity(),"hello",Toast.LENGTH_LONG).show();
        Log.e("<<<<","Click outside");
       grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
           [USER=1021285]@override[/USER]
           public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
              // String id=adapterView.getItemAtPosition(i).toString();
               String id= String.valueOf(adapterView.getSelectedItemId());
               Log.e("<<<<","Click");
               Toast.makeText(getActivity(),id+"hello",Toast.LENGTH_LONG).show();
           }
       });
        return view;
    }
}
Adapter for Gridview
Code:
public class GridAdapter extends BaseAdapter {

    ArrayList<Integer>pics_array;
    ArrayList<String>text_array;
    Context context;
    LayoutInflater inflater;

    public GridAdapter(FragmentActivity fraghome, ArrayList<Integer> pics_array, ArrayList<String> text_array) {
    this.pics_array=pics_array;
    this.text_array=text_array;
    this.context=fraghome;
    inflater= (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    [USER=1021285]@override[/USER]
    public int getCount() {
        return pics_array.size();
    }

    [USER=1021285]@override[/USER]
    public Object getItem(int i) {
        return i;
    }

    [USER=1021285]@override[/USER]
    public long getItemId(int i) {
        return i;
    }

    [USER=1021285]@override[/USER]
    public View getView(int i, View view, ViewGroup viewGroup) {
        Holder holder=new Holder();

        view=inflater.inflate(R.layout.gridcontent,null);
        holder.imgbtn=view.findViewById(R.id.img);
        holder.txtview=view.findViewById(R.id.txt);

        holder.imgbtn.setImageResource(pics_array.get(i));
        holder.txtview.setText(text_array.get(i));

        return view;
    }
    class Holder {
ImageButton imgbtn;
TextView txtview;
    }
}
FragHome.xml
Code:
<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"
    tools:context="com.admecmultimediainstitute.admec.Fraghome">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="550dp">

    <GridView
        android:id="@+id/grid"
        android:layout_width="match_parent"
        android:layout_height="500dp"
        android:numColumns="3"/>

    </RelativeLayout>
</ScrollView>
Content for Gridview
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:eek:rientation="vertical"
    android:layout_height="match_parent">
    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/img"
        android:focusable="false"
        android:focusableInTouchMode="false"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/txt"
        android:textAlignment="center"
        android:paddingLeft="10dp"/>

</LinearLayout>
Problem is that item click listener does not work
 
Last edited:
Here is the solution for you https://github.com/v777779/aad_20180326
I moved listener inside the Item, made code in Fraghome a little bit compact.

The gridcontent_alt.xml is not used, but this is the example for ImageView. You don't use ImageButton as button, so it's obvious to use ImageView and ?attr/selectableBackground used as clickable background of item.

Import repo direct into Android Studio or download as zip, unpack and use.
 
How to adjust the space in custom Toolbar?
Here is the Java Code
Code:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        toolbar.setLogo(R.drawable.toologo);
        toolbar.setTitle("ADMEC MULTIMEDIA INSTITUTE");
        toolbar.setPadding(0,0,0,0);
        toolbar.setContentInsetsAbsolute(0,0);
        setSupportActionBar(toolbar);
Here is the xml code for toolbar
Code:
<android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:layout_gravity="start"
            android:background="?attr/colorPrimary"
            android:longClickable="false"
            android:textAlignment="viewStart"
            app:logo="@drawable/toologo"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            app:title="ADMEC MULTIMEDIA INSTITUTE"
            android:padding="0dp"
            android:contentInsetLeft="0dp"
            android:contentInsetStart="0dp"
            app:contentInsetLeft="0dp"
            app:contentInsetStart="0dp"
            app:contentInsetStartWithNavigation="0dp"
            app:titleMargin="0dp" />
But space is unorganized still. Please help me to find some solution.
 
Last edited:
Sorry for late reply but still space is unorganized of the toolbar.
Code:
<android.support.v7.widget.Toolbar
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/toolbar"
    android:background="#de080a"
    app:title="LOGIN"
    android:textAlignment="center"
    app:titleTextColor="@color/cardview_light_background"
    android:layout_centerHorizontal="true"
    android:gravity="center"
    android:foregroundGravity="center"
    >
</android.support.v7.widget.Toolbar>
 [code]
 [code]
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setLogo(R.drawable.toologo);
toolbar.setTitle("ADMEC MULTIMEDIA INSTITUTE");
toolbar.setPadding(0,0,0,0);
//toolbar.setContentInsetsAbsolute(0,0);
setSupportActionBar(toolbar);
 [code]
Please give me a solution
 
Back
Top Bottom