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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:34:28+00:00 2026-05-22T11:34:28+00:00

Any one can help me in listview the first item should be selected by

  • 0

Any one can help me in listview the first item should be selected by default

package com.globalscholar.announcement;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.AdapterView.OnItemClickListener;

import com.globalscholar.R;

public class PublishAnnouncement extends ListActivity implements OnClickListener, OnItemClickListener{
    private ListView lViewPub;
    private String lv_items[] = {"Teachers" , "Students", "Administration"};
    RadioButton radioSSP;
    RadioButton radioPubAll1;
    Button backPub;
    Button donePub;
    int role = 0;

    //venkat
    int selectedPublishOption = -1;
    AudienceWrapper audienceDetails = null; 

    ArrayList<Boolean> checkedStates = new ArrayList<Boolean>();
    boolean checkedArray[];

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.publishannouncement);

    backPub=(Button)findViewById(R.id.buttPubBack);
    backPub.setOnClickListener(this);

    donePub=(Button)findViewById(R.id.buttPubDone);
    donePub.setOnClickListener(this);

    radioSSP=(RadioButton)findViewById(R.id.radioPubSSM);
    radioSSP.setOnClickListener(this);

    radioPubAll1=(RadioButton)findViewById(R.id.radioPubAll);
    radioPubAll1.setOnClickListener(this);
    radioPubAll1.setChecked(true);


    lViewPub = (ListView) findViewById(android.R.id.list);
    lViewPub.setOnItemClickListener(this);
    //  Set option as Multiple Choice. So that user can be able to select more the one option from list
    lViewPub.setAdapter(new ArrayAdapter<String>(this,
            R.layout.announcementlistviewstyle, lv_items));
    lViewPub.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    lViewPub.setVerticalScrollBarEnabled(false);
    getListView().setSelection(0);
    //venkat
    Bundle b = getIntent().getExtras();

    checkedStates.add(0, false);
    checkedStates.add(1, false);
    checkedStates.add(2, false);

    if(b!= null){
        audienceDetails = (AudienceWrapper) b.getSerializable("audienceDetails");
        selectedPublishOption = b.getInt("selectedPublishOption");
        //  checked = b.getLongArray("selectedPublishOptionsList");
        checkedArray =b.getBooleanArray("selectedPublishOptionsList");
        if(checkedArray!=null){
            Log.d("PA","Bundle Checked Array Size :"+checkedArray.length);
            for(int i=0;i<checkedArray.length;i++){
                checkedStates.set(i, checkedArray[i]);
                Log.w("PA","CheckedStatus index:"+i+"Status"+checkedStates.get(i));
                if(checkedStates.get(i))
                    lViewPub.setItemChecked(i, true);
            }
        }

        Log.d("selected publishoption in PublishAnnouncement--->", selectedPublishOption+"");
        if(selectedPublishOption == 0){
            radioPubAll1.setChecked(false);
            radioSSP.setChecked(true);
            lViewPub.setVisibility(BIND_AUTO_CREATE);
            //for checking the options                  
        }
    }
    //venkatend
    PublishAnnouncement.this.getListView().setOnItemClickListener(this);
}



public void onItemClick(AdapterView<?> arg0, View arg1, int position,
        long arg3) {        
    Log.d("onItemClick position in PublishAnnouncement----->",position+"");
    //role value updated in wrong way when u double click on Item
    //solved role problem in done button
    /* if(position == 0){
         role+= 4;
     }
     else if(position == 1){
         role+=8;
     }
     else if(position == 2){
         role+=2;
     }else{
         role+=14;
     }  
     Log.d("PA","Role :"+role);*/

    //venkat for selected publishes
    boolean currentlyChecked = checkedStates.get(position);  
    checkedStates.set(position, !currentlyChecked); 
    if(checkedArray!=null)
        checkedArray[position] = !currentlyChecked;



}

public void onClick(View v) {

    switch (v.getId()) {
    case R.id.radioPubSSM:
        lViewPub.setVisibility(BIND_AUTO_CREATE);
        break;
    case R.id.buttPubBack:
        onKeyDown(KeyEvent.KEYCODE_BACK, 
                new KeyEvent(KeyEvent.ACTION_DOWN,
                        KeyEvent.KEYCODE_BACK));
        break;
    case R.id.buttPubDone:
        //venkat
        int allSelect = 0;
        int sppCount=0;
        //venkatend
        Intent newPubDone= new Intent(PublishAnnouncement.this,Audience.class);
        Bundle b = new Bundle();
        if(radioPubAll1.isChecked()){
            role = 14;
            //venkat
            allSelect = 1;
        }else if(radioSSP.isChecked()){
            int len = checkedStates.size();     
            if(checkedArray == null)
                checkedArray = new boolean [len];
            for(int i=0;i<len;i++){
                checkedArray[i] = checkedStates.get(i);
                if(checkedStates.get(i)==true){
                    sppCount++;
                }
            }
            Log.d("PA","Count :"+sppCount);
        }
        if(sppCount==0 && radioSSP.isChecked()){
            AlertDialog.Builder alertBox = new AlertDialog.Builder(this);
            alertBox.setMessage("Please select Specific Memebers");
            alertBox.setNeutralButton("Ok", null);
            alertBox.show();

        }else{
            b.putInt("SelectedPublishOption", allSelect);
            int finalRole = 0;
            if(allSelect== 0){
                // b.putLongArray("SelectedPublishOptionsList", checked);
                b.putBooleanArray("SelectedPublishOptionsList", checkedArray);
                if(checkedArray!=null){
                    if(checkedArray[0]){
                        finalRole+=4;
                    }
                    if(checkedArray[1]){
                        finalRole+=8;
                    }
                    if(checkedArray[2]){
                        finalRole+=2;
                    }
                }
                Log.d("PA","After selecting final Role Value :"+finalRole);
                if(audienceDetails!=null)
                    audienceDetails.setRoleValue(finalRole);

            }
            b.putInt("role", finalRole);
            //venkatend
            newPubDone.putExtras(b);
            setResult(RESULT_OK, newPubDone);
            System.out.println("Role value is" + role);
            finish();

        }
        break;
    case R.id.radioPubAll:
        lViewPub.setVisibility(-1);

        //venkat testing logic
        if(checkedArray!=null){
            int len= checkedArray.length;
            if(len > 0){
                for(int i=0;i<len;i++){                             
                    lViewPub.setItemChecked(i, false);
                    System.out.println("all selected Position selected "+checkedArray[i]);
                }
            }
        }
        break;
    default:
        break;
    }
}
}

thanks

  • 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-22T11:34:29+00:00Added an answer on May 22, 2026 at 11:34 am

    Have you tried to use:

        ListView lv = getListView();
        lv.setFocusable(true);
        lv.setFocusableInTouchMode(true);
        lv.setSelection(0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can any one help me convert the below code to LINQ? Select Catg,Count(*) From
can any one help me with code that subtract 1 from a digit stored
can any one help me in creating a regular expression for password validation. The
Can any one help me how to sort rows by relevance for the following
I am new in Pocket PC and Smart phone. so can any one help
Can any one of you help me in converting an windows dll file in
can any one help me to display set of results in my app in
How can I copy selected items from one listview to another on button click..??
Can I have a ListView where I can customize the first cell, and then
Wondering if anyone can help me with this annoying but trivial (in terms of

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.