How to get all items in listview? - android

I've implemented one code to scan the wifi networks and display them in the list. After selecting one of the wifi networks from the list, I have added selected network in another activity in another ListView.
Now when I restart the app and again scan the wifi networks, I'm getting that network also which I have selected before and added in the list.
(In one activity I'm searching available wifi networks and in other activity I have added list of that selected networks)
So my question is that, how to hide that network which I have already added in list view?
This is my first activity, here i have displayed the added device in listview
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = (Button)findViewById(R.id.btnAdd);
btn.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View view)
{
Intent intent = new Intent(MainActivity.this,Second.class);
startActivity(intent);
finish();
}
});
try
{
listView = (ListView)findViewById(R.id.device_list);
devicesNameEspNum = new ArrayList<>();
devices = new Devices();
devicesList = alldeviceList();
for(int i=0; i<devicesList.size(); i++)
{
devices = devicesList.get(i);
devicesNameEspNum.add(devices);
}
devicesAdapter = new DevicesAdapter(MainActivity.this,devicesNameEspNum);
listView.setAdapter(devicesAdapter);
devicesAdapter.notifyDataSetChanged();
}
catch (NullPointerException ex)
{
ex.printStackTrace();
}
listView.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> adapter, View view, int position, long id)
{
Intent intent = new Intent(MainActivity.this,Fourth.class);
String selected = ((TextView) view.findViewById(R.id.deviceNamList)).getText().toString();
intent.putExtra("DEVICE_ID",selected);
startActivity(intent);
finish();
}
});
final LocationManager manager = (LocationManager) getSystemService( Context.LOCATION_SERVICE );
if ( !manager.isProviderEnabled( LocationManager.GPS_PROVIDER ) )
{
Toast.makeText(this, "****", Toast.LENGTH_SHORT).show();
}
}
public static List<Devices> alldeviceList()
{
return new Select().from(Devices.class).execute();
}
This is my second activity to scan nearby wifi networks
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
list=getListView();
mainWifiObj = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
if(mainWifiObj != null)
{
mainWifiObj.setWifiEnabled(true);
}
wifiReciever = new WifiScanReceiver();
mainWifiObj.startScan();
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)
{
requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},1000);
}
else
{
LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
}
// listening to single list item on click
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// selected item
String ssid = ((TextView) view).getText().toString();
connectToWifi(ssid);
Toast.makeText(Second.this,"Wifi SSID : "+ssid,Toast.LENGTH_SHORT).show();
}
});
}
This is the class:
class WifiScanReceiver extends BroadcastReceiver
{
#SuppressLint("UseValueOf")
public void onReceive(Context c, Intent intent)
{
List<ScanResult> wifiScanList = mainWifiObj.getScanResults();
System.out.println("Wifi Scan Result: "+wifiScanList);
wifis = new String[wifiScanList.size()];
for(int i = 0; i < wifiScanList.size(); i++)
{
wifis[i] = ((wifiScanList.get(i)).toString());
}
String filtered[] = new String[wifiScanList.size()];
int counter = 0;
for (String eachWifi : wifis) {
String[] temp = eachWifi.split(",");
filtered[counter] = temp[0].substring(5).trim();//+"\n" + temp[2].substring(12).trim()+"\n" +temp[3].substring(6).trim();//0->SSID, 2->Key Management 3-> Strength
counter++;
}
System.out.println("Filtered :"+filtered);
list.setAdapter(new ArrayAdapter<String>(getApplicationContext(),R.layout.list_item,R.id.label, filtered));
}
}

What's about this ?
displayed.addAll(allItems.filter { !it.equals("abc") })

Related

How to convert a Fragment to a Activity Android?

I have a working app using threads in fragments, the thing is I need to change the layout. It's not gonna be a Fragment anymore but a standard Activity.
My big problem is that I don't know exactly where to place what's in "onViewCreated" and "onCreateView" so it's crashing when I call "connect to device" which's placed on "onCreateView". Probably because it's too early or something.
#Nullable
#Override
public View onCreateView(final LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState){
View view;
view = inflater.inflate(R.layout.fragment_home_2, container, false);
//Linking layout views
connectToDevice = view.findViewById(R.id.connect_to_device);
startRecording = view.findViewById(R.id.start_recording);
stopRecording = view.findViewById(R.id.stop_recording);
connectedToDevice = view.findViewById(R.id.connected_to_device);
mAdapter = new DeviceListAdapter(container.getContext(), activeDevices);
imgEkoDevice = view.findViewById(R.id.img_ekodevice);
//Enable bluetooth and start scanning thread
BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
if (btAdapter != null && !btAdapter.isEnabled()) {
btAdapter.enable();
}
//Layout setup
connectedToDevice.setText(getResources().getString(R.string.welcome_to_scopefy));
//Thread setup to search for device
scanningThread = new Thread(){
#Override
public void run(){
Log.i(AppConstants.TAG, "scanning...");
LibCore.getInstance(ConnectDeviceActivity.this).startScanningForDevices(new EkoDeviceScan() {
#Override
public void foundDevice(BLEDevice bleDevice) {
//Log.i(AppPreferences.log, "foundDevice: " + bleDevice.toString());
if(activeDevices.isEmpty()){
//Adding first device to list
activeDevices.add(bleDevice);
}
else{
int i = 0;
newDevice = true;
//Checks if its already on the list
while(i < activeDevices.size() && newDevice){
if(activeDevices.get(i).getAddress().equals(bleDevice.getAddress())){
newDevice = false;
}
i++;
}
if(newDevice){
activeDevices.add(bleDevice);
}
}
//Show list and dismiss search dialog
if(connect){
showDeviceListDialog();
if(emptyListDialog != null){
emptyListDialog.dismiss();
}
connect = false;
}
}
});
}
};
LocalBroadcastManager.getInstance(ConnectDeviceActivity.this).registerReceiver(mDeviceReceiver, new IntentFilter(Parameters.DEVICE_REFRESH_DATA));
//Starting scanning background to speed up
if(LibCore.getInstance(ConnectDeviceActivity.this).getCurrentConnectedDevice() == null){
scanningThread.start();
LibCore.getInstance(ConnectDeviceActivity.this).setFiltering(true);
connected = false;
} else {
mEkoDevice = LibCore.getInstance(ConnectDeviceActivity.this).getCurrentConnectedDevice();
connected = true;
}
//Broadcast receiver for patientId
LocalBroadcastManager.getInstance(ConnectDeviceActivity.this).registerReceiver(mPatientReceiver, new IntentFilter(Parameters.PATIENT_ID));
//Listeners and receivers for device connection
LibCore.getInstance(ConnectDeviceActivity.this).setBatteryListener(new EkoDeviceBatteryLevel() {
#Override
public void deviceUpdatedBatteryLevel(float v) {
Log.i("HUEBR123", "updateou bat");
LocalBroadcastManager.getInstance(ConnectDeviceActivity.this).sendBroadcast(new Intent(Parameters.DEVICE_REFRESH_DATA).putExtra(Parameters.DEVICE_UPDATED_BATTERY_LEVEL, v));
}
});
LibCore.getInstance(ConnectDeviceActivity.this).setVolumeListener(new EkoDeviceVolume() {
#Override
public void deviceUpdatedVolumeLevel(int i) {
Log.i("HUEBR123", "updateou vol");
LocalBroadcastManager.getInstance(ConnectDeviceActivity.this).sendBroadcast(new Intent(Parameters.DEVICE_REFRESH_DATA).putExtra(Parameters.DEVICE_UPDATED_VOLUME_LEVEL, i));
}
});
//Settings
userSettingsDAO = new UserSettingsDAO(ConnectDeviceActivity.this);
settings = userSettingsDAO.getUserSettings();
//Button's listeners
connectToDevice.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
connect = true;
scanningThread.run();
showDeviceListEmptyDialog();
}
});
startRecording.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Log.i(AppConstants.TAG, "starting recording...");
stopped = false;
startRecording();
//startPlayRecordThroughEko();
startRecording.setVisibility(View.GONE);
stopRecording.setVisibility(View.VISIBLE);
recording = true;
settings = userSettingsDAO.getUserSettings();
settings.getRecordingLength();
Timer timer = new Timer();
TimerTask task = new StopRecordingTask();
timer.schedule(task, settings.getRecordingLength() * 1000);
Log.i(AppConstants.TAG, "#timer starting for " + settings.getRecordingLength() + " seconds");
}
});
stopRecording.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
try {
mEkoOutputAudioByteListener = null;
mAudioFileOutputStream.close();
writeWAVHeader(mCachedAudioRecordingFile, 4000);
//writeWAVHeader(mCachedECGRecordingFile, 500);
stopOutputtingAudioDataPoints();
} catch (Exception e) {
e.printStackTrace();
}
startRecording.setVisibility(View.VISIBLE);
stopRecording.setVisibility(View.GONE);
recording = false;
short[] output;
output = new short[outData.size() * 32];
for(int i=0; i<outData.size(); i++){
for(int j=0; j<32; j++){
output[i] = outData.get(i)[j];
}
}
Intent intent = new Intent(ConnectDeviceActivity.this, AuscultationActivity.class);
intent.putExtra("output", output);
intent.putExtra("patient-id", patientId);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Log.i(AppConstants.TAG, "OUPUTLEN: " + output.length);
if(!stopped) {
stopped = true;
startActivity(intent);
}
}
});
return view;
}
//This overridden method makes DynamicWaveformViews avoid crashing
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
dynamicWaveformView = (DynamicWaveformView) view.findViewById(R.id.dynamic_waveform_view);
dynamicWaveformView.init();
mAudioThread = new HandlerThread("AudioThread");
mAudioThread.start();
mAudioHandler = new Handler(mAudioThread.getLooper());
//updateView again for consistency (mDeviceBroadcast may be too much but still works)
updateView(connected);
}
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mEkoDevice = new EkoDevice("DUMMY_DEVICE", "0");
buyNow = findViewById(R.id.buyNow);
back = findViewById(R.id.back_icon);
back.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
}
});
buyNow.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(browserIntent);
}
});
changeAudioAmplitudeScaleFactor(8);
mPlayerManager = new PlayerManager();
mPlayerManager.onCreate();
LibCore.getInstance(ConnectDeviceActivity.this).setFiltering(true);
}
trying to place at the bottom of "onCreate" it gives me the following error:
PopupWindow $BadTokenException: Unable to add window — token null is not valid
Regarding you error
PopupWindow $BadTokenException: Unable to add window — token null is
not valid
Maybe add that code in the Activity onResume() lifecykle method instead of onCreate if it need to run more then one time
Move the scanningThread, BluetoothAdapter and LocalBroadcastManager LibCore everything to the 'onCreate()' . The 'onCreateView()' should only have the view = inflater.inflate(R.layout.fragment_home_2, container, false);
The onCreate() only initiate stuff hook up local variables views and set clicklisteners. Like all the one-time-stuff. Going from Fragment to Activity is basically almost the same since they have the same lifecykle methods
Check this nice explanation about the-android-lifecycle-cheat-sheet

Why Savedinstance values get null when returning back to that activity in Marshmallow?

I created an application which gets values from previous activity as extras and uses that values in that activity. And the values are then sent to another activity. But when I returned back from the moving activity to previous activity the extra values are becoming null.
For example, I get Values from Activity A to Activity B (some id and image id etc) Now, I sent that values to Activity C as Intent extras. Here in Activity C, I get the values (Initial Case)! Now when I press back to Activity B and Again moved to Activity C, I am not getting the values(some id and image id etc) in Activity C. This Happens in Marshmallow only. In Activity C name is getting from Server in Activity B and is Moved accordingly! This is working perfectly till lollipop! But this happens in Marshmallow!
My Activity B Fetchservices (Here it moves to another Activity code is:
public void fetchServices(){
mProgressBar.setVisibility(View.VISIBLE);
String android_id = Settings.Secure.getString(getContentResolver(),
Settings.Secure.ANDROID_ID);
String userid = prefs.getString("userId","0");
Log.e("USERID",userid);
Log.e("URL TOP UP", Constants.BASE_URL_SERVICE_LIST+"?deviceid="+android_id+"&userid="+userid +"&country="+countryname+"&countryid="+countryid);
RestClientHelper.getInstance().get(Constants.BASE_URL_SERVICE_LIST+"?deviceid="+android_id+"&userid="+userid+"&country="+countryname+"&countryid="+countryid, new RestClientHelper.RestClientListener() {
#Override
public void onSuccess(String response) {
Log.e("Resposnse",response);
mProgressBar.setVisibility(View.GONE);
parseResult(response);
mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
//Get item at position
GridItem item = (GridItem) parent.getItemAtPosition(position);
String myactivity = "com.mobeeloadpartner."+item.getGlobalActivity();
if(item.getGlobalActivity().equals("0") || item.getGlobalActivity() == null || ("").equals(item.getGlobalActivity())){
activity = Constants.getActivityClass("ComingSoon");
}
else{
activity = Constants.getActivityClass(item.getGlobalActivity());
}
Intent intent = new Intent(GlobalActivity.this, activity);
Log.e("Activity",item.getGlobalActivity());
intent.putExtra("country", countryname);
intent.putExtra("countryid", countryid);
intent.putExtra("countrycode", countrycode);
intent.putExtra("title", item.getTitle());
intent.putExtra("image", item.getImage());
intent.putExtra("serviceid", item.getServiceId());
//Start details activity
startActivity(intent);
}
});
}
#Override
public void onError(String error) {
}
});
}
Activity C onCreate Code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Fabric.with(this, new Crashlytics());
setContentView(R.layout.international_topup);
toolbar = (Toolbar) findViewById(R.id.tool_bar); // Attaching the layout to the toolbar object
setSupportActionBar(toolbar);
prefs = new PreferenceHelper(InternationalTopup.this);
loading = (CircleProgressBar) findViewById(R.id.loading);
check = new CheckInterNetConnection(InternationalTopup.this);
mGridView = (GridView) findViewById(R.id.gridView);
loading.setVisibility(View.INVISIBLE);
//this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
mGridData = new ArrayList<>();
mGridAdapter = new EloadGridViewAdapter(this, R.layout.grid_eload_amount, mGridData);
mGridView.setAdapter(mGridAdapter);
pd = new ProgressDialog(InternationalTopup.this);
isInternetPresent = check.isConnectingToInternet();
popup = (LinearLayout) findViewById(R.id.popup);
maintable = (TableLayout)findViewById(R.id.maintable);
tl = (TableLayout) findViewById(R.id.maintable);
noOps = (RelativeLayout) findViewById(R.id.noOps);
if (savedInstanceState == null) {
Bundle extras = getIntent().getExtras();
if(extras == null) {
countryname =null;
countryid = null;
countrycode = null;
} else {
countryname= extras.getString("country");
countryid= extras.getString("countryid");
countrycode= extras.getString("countrycode");
}
} else {
countryname= (String) savedInstanceState.getSerializable("country");
countryid= (String) savedInstanceState.getSerializable("countryid");
countrycode = (String) savedInstanceState.getSerializable("countrycode");
}
opimage = (ImageView)findViewById(R.id.opimage);
try {
countryid = countryid.toLowerCase();
}
catch(Exception e){
countryid = "0";
}
Picasso.with(getApplicationContext()).load(Constants.URL+"/app/countries/png250px/"+countryid+".png").fit().error(R.drawable.mobeeloadicon).into(opimage);
amount = (EditText)findViewById(R.id.amount);
amount.setText("0");
EditText mytext = (EditText)findViewById(R.id.phonenumber);
// mytext.setText(countrycode);
EditText code = (EditText)findViewById(R.id.code);
code.setText(countrycode);
code.setKeyListener(null);
mytext.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
public void onTextChanged(CharSequence s, int start,
int before, int count) {
operatorName = "Auto Fetch";
mGridAdapter.clear();
}
});
amount.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
public void onTextChanged(CharSequence s, int start,
int before, int count) {
localValue = "";
}
});
TextView countryName = (TextView)findViewById(R.id.countryname);
countryName.setText(countryname);
//amount.setEnabled(false);
if (isInternetPresent) {
} else {
Constants.showAlert(InternationalTopup.this,"Please check your internet connection and try again");
// SnackbarManager.show(Snackbar.with(InternationalTopup.this).text("Please check your internet connection and try again"));
}
}
Please help to sought out this issue!
Yeah!! That was a silly mistake! In developer option, there was an option to remove activity data when moving to activities! It was ON somehow! Keep it OFF!

not getting ListView Item in Android

When I can click on ListView item with new Activity, ListView is not opening. I'm not understand why it is not open.
public class ActivityListOfSearchIDProfiles extends AppCompatActivity implements AdapterView.OnItemClickListener {
private ListView mListOfProfiles;
private ArrayList<Registration> mArrayListOfRegistrations;
private SearchByIDAdapter mSearchByIDAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lay_activitylistview);
mListOfProfiles = (ListView) findViewById(R.id.listOFSerachProfiles);
Toolbar toolbar= (Toolbar) findViewById(R.id.toolbarCommon);
setSupportActionBar(toolbar);
toolbar.setTitleTextColor(Color.parseColor("#FFFFFF"));
toolbar.setNavigationIcon(R.drawable.ic_action_navigation_arrow_back_inverted);
getSupportActionBar().setIcon(R.mipmap.ic_action_account_circle);
getSupportActionBar().setTitle("Profile");
mArrayListOfRegistrations = new ArrayList<Registration>();
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
finish();
overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
}
});
final Intent intent = getIntent();
String hjID = intent.getStringExtra("hjID");
if (isConnected())
{
Toast.makeText(ActivityListOfSearchIDProfiles.this, "Profile:"+hjID, Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(ActivityListOfSearchIDProfiles.this, "No Internet Connection Available", Toast.LENGTH_SHORT).show();
}
new SearchByIDGETThread(ActivityListOfSearchIDProfiles.this, new HandlerRegisterSearchProfile(), hjID).execute();
System.out.println("With Thread");
mListOfProfiles.setOnItemClickListener(this);
}
public boolean isConnected() {
ConnectivityManager conManager = (ConnectivityManager) getSystemService(Activity.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = conManager.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected()) {
return true;
} else {
return false;
}
}
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
System.out.println("Open Listview Item");
Registration mRegistration = mArrayListOfRegistrations.get(i);
System.out.println("In listView Item");
Intent intent = new Intent(ActivityListOfSearchIDProfiles.this, ActivityShowProfileDetails.class);
intent.putExtra("fname", mRegistration.getFname());
intent.putExtra("lname", mRegistration.getLname());
intent.putExtra("hjID", mRegistration.getData());
intent.putExtra("gender", mRegistration.getGender());
intent.putExtra("dob", mRegistration.getDob());
intent.putExtra("tob", mRegistration.getTob());
intent.putExtra("age", mRegistration.getAge());
intent.putExtra("height", mRegistration.getHeight());
intent.putExtra("complexion", mRegistration.getComplexion());
intent.putExtra("blood_group", mRegistration.getBlood_group());
intent.putExtra("spect", mRegistration.getSpect());
intent.putExtra("ph_dis", mRegistration.getPh_dis());
intent.putExtra("nri", mRegistration.getNri());
intent.putExtra("caste", mRegistration.getCast());
intent.putExtra("rashi", mRegistration.getRashi());
intent.putExtra("hob", mRegistration.getHob());
intent.putExtra("city", mRegistration.getCity());
intent.putExtra("state", mRegistration.getState());
intent.putExtra("edu", mRegistration.getEdu());
intent.putExtra("occupation", mRegistration.getOcc());
intent.putExtra("place_occupation", mRegistration.getPlace_occ());
intent.putExtra("income", mRegistration.getIncome());
intent.putExtra("cat", mRegistration.getCat());
intent.putExtra("father", mRegistration.getFather());
intent.putExtra("mother", mRegistration.getMother());
intent.putExtra("father_name", mRegistration.getFather_name());
intent.putExtra("mother_name", mRegistration.getMother_name());
intent.putExtra("mama_name", mRegistration.getMama_name());
intent.putExtra("mama_place", mRegistration.getMama_place());
intent.putExtra("rel_name", mRegistration.getRel_name());
intent.putExtra("native_place", mRegistration.getNative_place());
intent.putExtra("no_brothers", mRegistration.getNo_brothers());
intent.putExtra("no_mar_bro", mRegistration.getNo_sisters());
intent.putExtra("no_sisters", mRegistration.getNo_mar_bro());
intent.putExtra("no_mar_sis", mRegistration.getNo_mar_sis());
intent.putExtra("parent_occ", mRegistration.getParent_occ());
intent.putExtra("family_property", mRegistration.getFamily_prop());
intent.putExtra("expect", mRegistration.getExpectations());
intent.putExtra("photo", mRegistration.getPhoto());
intent.putExtra("photo2", mRegistration.getPhoto2());
System.out.println("In ITem Search");
System.out.println(intent.putExtra("family_property", mRegistration.getFamily_prop()));
startActivity(intent);
}
}
You should setAdapter such as;
mListOfProfiles.setAdapter(
new CustomProfileAdapter(this,mArrayListOfRegistrations));
Without setting adapter you cannot inflate you list.
If your data set on the ListView properly then please use the switch case in the Onitemclick function of the ListView. Like below code:-
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
switch (adapterView.getId())
{
case R.id.listOFSerachProfiles:
Intent intent = new Intent(ActivityListOfSearchIDProfiles.this, ActivityShowProfileDetails.class);
intent.putExtra("fname", mRegistration.getFname());
intent.putExtra("lname", mRegistration.getLname());
intent.putExtra("hjID", mRegistration.getData());
intent.putExtra("gender", mRegistration.getGender());
intent.putExtra("dob", mRegistration.getDob());
intent.putExtra("tob", mRegistration.getTob());
intent.putExtra("age", mRegistration.getAge());
intent.putExtra("height", mRegistration.getHeight());
intent.putExtra("complexion", mRegistration.getComplexion());
intent.putExtra("blood_group", mRegistration.getBlood_group());
intent.putExtra("spect", mRegistration.getSpect());
intent.putExtra("ph_dis", mRegistration.getPh_dis());
intent.putExtra("nri", mRegistration.getNri());
intent.putExtra("caste", mRegistration.getCast());
intent.putExtra("rashi", mRegistration.getRashi());
intent.putExtra("hob", mRegistration.getHob());
intent.putExtra("city", mRegistration.getCity());
intent.putExtra("state", mRegistration.getState());
intent.putExtra("edu", mRegistration.getEdu());
intent.putExtra("occupation", mRegistration.getOcc());
intent.putExtra("place_occupation", mRegistration.getPlace_occ());
intent.putExtra("income", mRegistration.getIncome());
intent.putExtra("cat", mRegistration.getCat());
intent.putExtra("father", mRegistration.getFather());
intent.putExtra("mother", mRegistration.getMother());
intent.putExtra("father_name", mRegistration.getFather_name());
intent.putExtra("mother_name", mRegistration.getMother_name());
intent.putExtra("mama_name", mRegistration.getMama_name());
intent.putExtra("mama_place", mRegistration.getMama_place());
intent.putExtra("rel_name", mRegistration.getRel_name());
intent.putExtra("native_place", mRegistration.getNative_place());
intent.putExtra("no_brothers", mRegistration.getNo_brothers());
intent.putExtra("no_mar_bro", mRegistration.getNo_sisters());
intent.putExtra("no_sisters", mRegistration.getNo_mar_bro());
intent.putExtra("no_mar_sis", mRegistration.getNo_mar_sis());
intent.putExtra("parent_occ", mRegistration.getParent_occ());
intent.putExtra("family_property", mRegistration.getFamily_prop());
intent.putExtra("expect", mRegistration.getExpectations());
intent.putExtra("photo", mRegistration.getPhoto());
intent.putExtra("photo2", mRegistration.getPhoto2());
System.out.println("In ITem Search");
System.out.println(intent.putExtra("family_property", mRegistration.getFamily_prop()));
startActivity(intent);
break;
}
}
Hope this code help you :-)
Its better to extends ListActivity to ActivityListOfSearchIDProfiles. Then create ArrayAdapter or your custom listAdapter and add your data list to adapter. Then set Adapter to your listview.

Android - Listview Items position decreasing

I'm building an App that receives all wifi networks arround my house.
All wifi networks are being listed inside a Listview.
Now I would like to open a new activity when some listview item is clicked. But before that I would like to get the SSID from the selected Item.
I'm using onItemClick to get the position from the item and is working fine. The problem that I'm getting is that when I click at some item, I get a different SSID from the current selected item, the values are being desplayed like that:
WIFI 1 - When I click here I get the SSID from WIFI 3
WIFI 2 - When I click here I get the SSID from WIFI 2
WIFI 3 - When I click here I get the SSID from WIFI 1
Instead of getting the SSID from the wifi 1 when I click at wifi one and etc.
Can you guys check what am I doing wrong?
My code:
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textStatus = (TextView) findViewById(R.id.textView1);
buttonScan = (Button) findViewById(R.id.button1);
lv = (ListView)findViewById(R.id.text);
lv.setClickable(true);
wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
if (wifi.isWifiEnabled() == false)
{
Toast.makeText(getApplicationContext(), "wifi is disabled..making it enabled", Toast.LENGTH_LONG).show();
wifi.setWifiEnabled(true);
}
this.adapter = new SimpleAdapter(MainActivity.this, arraylist, android.R.layout.simple_list_item_1, new String[] { ITEM_KEY }, new int[] { android.R.id.text1 });
lv.setAdapter(this.adapter);
registerReceiver(new BroadcastReceiver()
{
#Override
public void onReceive(Context c, Intent intent)
{
results = wifi.getScanResults();
size = results.size();
}
}, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
}
#Override
protected void onResume() {
super.onResume();
final Handler handler = new Handler();
Runnable refresh = new Runnable() {
#Override
public void run() {
test();
handler.postDelayed(this, 8000);
}
};
handler.postDelayed(refresh, 2000);
}
private void test() {
{
arraylist.clear();
wifi.startScan();
Toast.makeText(this, "Scanning...." + size, Toast.LENGTH_SHORT).show();
try
{
size = size - 1;
lv.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Log.e("", "" + results.get(arg2).SSID);
}
});
while (size >= 0)
{
LinkedHashMap<String, String> item = new LinkedHashMap<String, String>();
String BSSID = results.get(size).BSSID;
int frequency = results.get(size).frequency;
if(!results.get(size).SSID.equals("FET")) {
item.put(ITEM_KEY, results.get(size).SSID.concat(""));
arraylist.add(item);
}
size--;
adapter.notifyDataSetChanged();
}
}
catch (Exception e)
{ }
}
}
}
Reverse the order in which you add your list items to arraylist
try
{
size = 0;
...
while (size < results.size())
{
...
arraylist.add(item);
...
size++;
...
}
}

Android OnItemCLickListener not working in listview

I am new to android programming.I am developing an app in which when user clicks on any ListView item it should go to Google maps app and display pin for that address on the map. But when I click on any item nothing happens.
Following is my display Activity.
public class DisplayActivity extends Activity implements OnItemClickListener{
ListView listView;
private String tag_name;
public List<NameAddress> nameAddressList;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display);
listView = (ListView) findViewById(R.id.list);
Intent intent = getIntent();
if(intent!= null)
{
tag_name = intent.getStringExtra("DashItemName");
setTitle("List of " +tag_name+ " addresses");
}
nameAddressList = null;
try {
XMLDOMParserHandler parser = new XMLDOMParserHandler(tag_name);
nameAddressList = parser.parseXML(getAssets().open("data.xml"));
ArrayAdapter<NameAddress> adapter =
new ArrayAdapter<NameAddress>(this,R.layout.list_item, nameAddressList);
listView.setAdapter(adapter);
} catch (IOException e) {
e.printStackTrace();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.display, menu);
return true;
}
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
// Build the intent
String address = nameAddressList.get(position).toString();
address = "geo:0,0?q=" + address;
String query = URLEncoder.encode(address, "utf-8");
Uri location = Uri.parse(query);
Intent mapIntent = new Intent(Intent.ACTION_VIEW, location;
mapIntent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
// Verify it resolves
PackageManager packageManager = getPackageManager();
List<ResolveInfo> activities = packageManager.queryIntentActivities(mapIntent, 0);
boolean isIntentSafe = activities.size() > 0;
// Start an activity if it's safe
if (isIntentSafe) {
startActivity(mapIntent);
}
else
{
Toast.makeText(this, "Please install google maps app", Toast.LENGTH_LONG).show();
}
}
}
Please suggest me a way to solve this problem.
Please suggest me a way to solve this problem.
It doesn't work for you because you forgot to assign listener to ListView:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display);
listView = (ListView) findViewById(R.id.list);
listView.setOnItemClickListener(this);
...
}
Now, it will work for you.
You forgot to set the listener to your ListView.
Just after the creation of listView you should add:
listView.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//your onItemClick code
}
}

Categories

Resources