• 0

android java help, please


Question

I have this bit of code and I am trying to get it working ... can you help me with the issues I have? which is to do with the R.layout... also point out any tips or hints on where to improve? I am just playing around at the moment getting used to it


package com.example.webu;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
public class MainActivity extends Activity {
SimpleAdapter adapter;
ArrayList<HashMap<String, String>> arraylist = new ArrayList<HashMap<String, String>>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo at = cm.getActiveNetworkInfo();

final TextView tni = (TextView)findViewById(R.id.textView1);
ListView lv = (ListView)findViewById(R.id.listView1);


WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
if(wifi.isWifiEnabled()) {
List<ScanResult> scanResults = wifi.getScanResults();
for(ScanResult scanRes : scanResults) {
this.adapter = new SimpleAdapter(MainActivity.this, arraylist, R.layout.rowLayout, new String[] { ITEM_KEY }, new int[] { R.id.list_value });
lv.setAdapter(this.adapter);
//tni.setText(scanRes.toString());
}
}
//tni.setText(at.toString());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
[/CODE]

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.