Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7612453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:54:56+00:00 2026-05-31T01:54:56+00:00

I have written following to show my data into grid view. This is the

  • 0

I have written following to show my data into grid view. This is the procedure of my code.

In onCreate()

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_newslist);
// Initializing NewsAdapter in order to loading the list of NEWS items
    newsAdapter = new NewsAdapter(this);
// Initializing grid view to show news
        gridView = (GridView) findViewById(R.id.news_gridview);
        gridView.setAdapter(newsAdapter);
        gridView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                Toast.makeText(NewsList.this, "" + position, Toast.LENGTH_SHORT).show();
            }
        });

Then in onStart() I’ll get XML data from server then parse it and final parsed data will be stored in “parsedList” (100% I have data in this variable because I saw it in logcat).

@Override
    protected void onStart() {
        super.onStart();
        String strNewsContent = "***";

        ...

        newsAdapter.setData(parsedList);
        newsAdapter.notifyDataSetChanged();
    }

Finally this is my “NewsAdapter”:

public class NewsAdapter extends BaseAdapter {

    private LayoutInflater myInflater;
    private NewsFeedItemList itemList;


    public NewsAdapter(Context c) {
        myInflater = LayoutInflater.from(c);
    }

    public void setData(NewsFeedItemList newsFeedItemList){
        itemList = newsFeedItemList;

        Log.i("NewsAdapter", "Parsed list passed to the adapter.");
    }

    @Override
    public int getCount() {
        return 0;
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent){
        ViewHolder holder;

        if (convertView == null) {
            convertView = myInflater.inflate(R.layout.grid_news, null);
            holder = new ViewHolder();
            holder.ivIcon = (TextView) convertView.findViewById(R.id.news_icon);
            holder.tvLabel = (TextView) convertView.findViewById(R.id.news_label);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.ivIcon.setText(itemList.getImage().get(position));
        holder.tvLabel.setText(itemList.getTitle().get(position));

        Log.i("Position is>>>>:", Integer.toString(position));

        return convertView;
    }   

    static class ViewHolder {
        TextView ivIcon;
        TextView tvLabel;
    }

}

The format of “grid_news” is like this

<?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="wrap_content" >

    <TextView
        android:id="@+id/news_icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/menu_contentdescription"
        android:layout_centerHorizontal="true" />

    <TextView
        android:id="@+id/news_label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:textColor="#ffffff"
        android:textSize="15sp"
        android:textStyle="bold"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:paddingBottom="10dip" />

</RelativeLayout>

I have no idea why I can’t see the result in my emulator/device.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T01:54:57+00:00Added an answer on May 31, 2026 at 1:54 am

    I think it is because of getCount() returning 0; shouldn’t it be itemList.size()? in news NewsAdapter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have written the following code class Program { static void Main(string[] args) {
I have to show the filenames using given template. I've written the following code:
I have written following code to attach gesture recogniser to multiple imageviews. [imageview1 setUserInteractionEnabled:YES];
I am trying my hands on WPF MVVM. I have written following code in
I have written the following code, CrystalDecisions.CrystalReports.Engine.ReportDocument report = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); report.Load(@C:\Users\XXX\Desktop\Backup1\Project\ReportsFolder\ReportSalesInvoice.rpt); Report works
I have written a following code to get just the file name without extension
I have written the following code choice /m Do you want to add another
I need to show an overlay on button click.To achieve this i have written
I have written following code for getting location name : UseGpsActivity.java public class UseGpsActivity
I have written following code to get location name package demo.gps.locname; import java.io.IOException; import

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.