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 8491379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:24:24+00:00 2026-06-10T22:24:24+00:00

i have an app that is showing data in listview ,but i want first

  • 0

i have an app that is showing data in listview ,but i want first row to be inflated by diferent layout , and i did that but since there is gona be a big number of listitems , i want to optimize listview and there is issue. i cant optimize listview when iam filling listview on that way , so how can i put content that should go in fist row inside listview header witch is inflated by some layout ,here is the code of Adapter

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.main);

    LinearLayout content = (LinearLayout) findViewById(R.id.content);
    LinearLayout refLayout = (LinearLayout) findViewById(R.id.refLayout);

    refLayout.setVisibility(View.GONE);

    mBtnNaslovnica = (Button) findViewById(R.id.mBtnNaslovnica);
    mBtnNaslovnica.setSelected(true);
    TextView txtView=(TextView) findViewById(R.id.scroller);
txtView.setSelected(true);
    loadPage();
    ImageButton mBtnRefresh = (ImageButton) findViewById(R.id.btnRefresh);
    mBtnRefresh.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            new LoadingTask().execute(URL);
        }
    });

}

public void loadPage(){

    ArrayList<HashMap<String, String>> homeList = new ArrayList<HashMap<String, String>>();



        JSONObject jsonobj;
        try {
            jsonobj = new JSONObject(getIntent().getStringExtra("json"));
            JSONObject datajson = jsonobj.getJSONObject("data");
            JSONArray news = datajson.getJSONArray(TAG_NEWS);
            JSONArray actual = datajson.getJSONArray("actual");
            for(int i = 0; i < news.length(); i++){
                JSONObject c = news.getJSONObject(i);

                // Storing each json item in variable
                String id = c.getString(TAG_ID);
                String title = c.getString(TAG_TITLE);
                String story = c.getString(TAG_STORY);
                String shorten = c.getString(TAG_SH_STORY);
                String author = c.getString(TAG_AUTHOR);
                String datetime = c.getString(TAG_DATETIME);
                String img = c.getString(TAG_IMG);
                String big_img = c.getString(TAG_BIG_IMG);



                // creating new HashMap
                HashMap<String, String> map = new HashMap<String, String>();

                // adding each child node to HashMap key => value
                map.put(TAG_ID, id);
                map.put(TAG_TITLE, title);
                map.put(TAG_STORY, story);
                map.put(TAG_IMG, img);
                map.put(TAG_BIG_IMG, big_img);
                map.put(TAG_DATETIME, datetime);
                map.put(TAG_AUTHOR, author);

                // adding HashList to ArrayList
                homeList.add(map);}
            for(int i = 0; i < actual.length(); i++){
                JSONObject c = actual.getJSONObject(i);

                // Storing each json item in variable
                String id = c.getString(TAG_ACT_TIME);
                String body = c.getString(TAG_ACT_BODY);
                String anews = " | "+ id+ " " + body;
                String cur_anews = ((TextView) findViewById(R.id.scroller)).getText().toString();
                String complete = anews + cur_anews;
                TextView anewstv = (TextView) findViewById(R.id.scroller);
                anewstv.setText(complete);

                }
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }






    list=(ListView)findViewById(R.id.list);

    // Getting adapter by passing xml data ArrayList
    adapter=new LazyAdapter(this, homeList);        
    list.setAdapter(adapter);


    // Click event for single list row
    list.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
            String cur_title = ((TextView) view.findViewById(R.id.title)).getText().toString();
            String cur_story = ((TextView) view.findViewById(R.id.einfo2)).getText().toString();
            String cur_author = ((TextView) view.findViewById(R.id.einfo1)).getText().toString();
            String cur_datetime  = ((TextView) view.findViewById(R.id.tVdatetime)).getText().toString();
            String cur_actual  = ((TextView) findViewById(R.id.scroller)).getText().toString();
            ImageView cur_img = (ImageView) view.findViewById(R.id.list_image);
            String cur_img_url = (String) cur_img.getTag();

            Intent i = new Intent("com.example.androidhive.CURENTNEWS");
            i.putExtra("CUR_TITLE", cur_title);
            i.putExtra("CUR_STORY", cur_story);
            i.putExtra("CUR_AUTHOR", cur_author);
            i.putExtra("CUR_DATETIME", cur_datetime);
            i.putExtra("CUR_IMG_URL", cur_img_url);
            i.putExtra("CUR_ACTUAL", cur_actual);
            startActivity(i);
        }
    });     
}   

public void reloadPage(String jsonstring){
    ArrayList<HashMap<String, String>> homeList = new ArrayList<HashMap<String, String>>();



    JSONObject jsonobj;
    try {
        jsonobj = new JSONObject(jsonstring);
        JSONObject datajson = jsonobj.getJSONObject("data");
        JSONArray news = datajson.getJSONArray(TAG_NEWS);
        JSONArray actual = datajson.getJSONArray("actual");
        for(int i = 0; i < news.length(); i++){
            JSONObject c = news.getJSONObject(i);

            // Storing each json item in variable
            String id = c.getString(TAG_ID);
            String title = c.getString(TAG_TITLE);
            String story = c.getString(TAG_STORY);
            String shorten = c.getString(TAG_SH_STORY);
            String author = c.getString(TAG_AUTHOR);
            String datetime = c.getString(TAG_DATETIME);
            String img = c.getString(TAG_IMG);
            String big_img = c.getString(TAG_BIG_IMG);


            // creating new HashMap
            HashMap<String, String> map = new HashMap<String, String>();

            // adding each child node to HashMap key => value
            map.put(TAG_ID, id);
            map.put(TAG_TITLE, title);
            map.put(TAG_STORY, story);
            map.put(TAG_IMG, img);
            map.put(TAG_BIG_IMG, big_img);
            map.put(TAG_DATETIME, datetime);
            map.put(TAG_AUTHOR, author);

            // adding HashList to ArrayList
            homeList.add(map);}
        for(int i = 0; i < actual.length(); i++){
            JSONObject c = actual.getJSONObject(i);

            // Storing each json item in variable
            String id = c.getString(TAG_ACT_TIME);
            String body = c.getString(TAG_ACT_BODY);
            String anews = " | "+ id+ " " + body;
            String cur_anews = ((TextView) findViewById(R.id.scroller)).getText().toString();
            String complete = anews + cur_anews;
            TextView anewstv = (TextView) findViewById(R.id.scroller);
            anewstv.setText(complete);

            }
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }






list=(ListView)findViewById(R.id.list);

// Getting adapter by passing xml data ArrayList
adapter=new LazyAdapter(this, homeList);        
list.setAdapter(adapter);


// Click event for single list row
list.setOnItemClickListener(new OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
        String cur_title = ((TextView) view.findViewById(R.id.title)).getText().toString();
        String cur_story = ((TextView) view.findViewById(R.id.einfo2)).getText().toString();
        String cur_author = ((TextView) view.findViewById(R.id.einfo1)).getText().toString();
        String cur_datetime  = ((TextView) view.findViewById(R.id.tVdatetime)).getText().toString();
        String cur_actual  = ((TextView) findViewById(R.id.scroller)).getText().toString();
        ImageView cur_img = (ImageView) view.findViewById(R.id.list_image);
        String cur_img_url = (String) cur_img.getTag();

        Intent i = new Intent("com.example.androidhive.CURENTNEWS");
        i.putExtra("CUR_TITLE", cur_title);
        i.putExtra("CUR_STORY", cur_story);
        i.putExtra("CUR_AUTHOR", cur_author);
        i.putExtra("CUR_DATETIME", cur_datetime);
        i.putExtra("CUR_IMG_URL", cur_img_url);
        i.putExtra("CUR_ACTUAL", cur_actual);
        startActivity(i);
    }
});
}

public void startNewActivity(){

}
public class LoadingTask extends AsyncTask<String, Object, Object>{
    XMLParser parser = new XMLParser();
    JSONParser jParser = new JSONParser();
    LinearLayout content = (LinearLayout) findViewById(R.id.content);
    LinearLayout refLayout = (LinearLayout) findViewById(R.id.refLayout);

    protected void onPreExecute(){
        content.setClickable(false);
        refLayout.setVisibility(View.VISIBLE);
    }

    @Override
    protected Object doInBackground(String... params) {
        // TODO Auto-generated method stub


        String URL = params[0];
        JSONObject json = jParser.getJSONFromUrl(URL);
        //String xml = parser.getXmlFromUrl(URL); // getting XML from URL
         // getting DOM element
        return json;
    }

    protected void onPostExecute(Object result){
        String json;
        json = result.toString();
        reloadPage(json);
        refLayout.setVisibility(View.GONE);
    }


}



}
  • 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-06-10T22:24:25+00:00Added an answer on June 10, 2026 at 10:24 pm

    If I got your point – you can go with 2 approaches:

    1. Add headerView to the list. That is just easy as inflate your View and pass it to
      addHeaderView(View) of your List. Note: you must add this view before setting the adapter, or it will throw the exception.

    2. However, as your ‘header’ is representing the same data as all other items, but has different layout – I suggest not to use Header here. Instead, try to implement getItemViewType() in your adapter. http://developer.android.com/reference/android/widget/BaseAdapter.html#getItemViewType(int)
      If you’ll do – you’ll have ability to check which type of layout to return in getView() method. And Android will take care of optimizing and reusing your inflated Views for you, so you can be sure that convertView, passed to your getView will be of the right type and layout.

    Please let me know if I should explain with more details.

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

Sidebar

Related Questions

have an app that finds your GPS location successfully, but I need to be
I have an app that received JSON data from the server. Currently when I
I have an app that allows users to upload large data files and then
My iPhone app relies on a vendor's XML feed to provide data. But that
I have an app that uses a UINavigationController as its main way of showing
I Have a Silverlight WPF app that shows tabs of data in this case
I have an MVC2 C#. Net web app that is storing data in html
I'm currently working on an app using MVVM that needs to have some data
I have an app that pulls data from a server where the timestamp is
I have created a ListActivity in which I am showing some data ,but after

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.