SimpleAdapter adapter;
inside on create:
String [] from=new String []{"text"};
int [] to=new int []{R.id.TextView01};
List<HashMap<String, String>> fillMaps = listForSimpleAdapter();// new
adapter = new SimpleAdapter(this, fillMaps, R.layout.listems,
from, to) {
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
return v;
}
};
reacharchlist.setAdapter(adapter);
outsidefunction:
private List<HashMap<String, String>> listForSimpleAdapter(){
List<HashMap<String, String>> fillMaps = new ArrayList<HashMap<String, String>>();
for(int i=0;i<textarray.length;i++)
{
HashMap<String, String> map = new HashMap<String, String>();
String text1=textarray[i];
map.put("text", text1);
fillMaps.add(map);
}
return fillMaps;
}
--------------------------------------------------------------------------------------------------------------
/*package mon.ctacts;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.SortedMap;
import montact.shared.token.MontactToken;
import org.jivesoftware.smack.Roster;
import org.jivesoftware.smack.RosterEntry;
import org.jivesoftware.smack.RosterListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smackx.packet.VCard;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.settingpage.SettingPage;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class TravellistActivity extends Activity implements OnClickListener
{
int i;
// TextView location;
// TextView adress;
// TextView date;
*//** Called when the activity is first created. *//*
public String one = "1";
public String zero = "0";
// public String ="1";
private static final String LOG_KEY = "TEST";
public String Skype = "skype";
public String Gtalk = "gtalk";
// public String Date = "sep 27 2010";
public String title = "title";
public String status;
public String Imcode;
Button login;
Button upload;
Button store;
String Dname;
String Dimage;
String Ddescription;
String Ddate;
String Dlocation;
String Dlatitude;
String Dlongitude;
String ldescription;
String limages;
String Imagename;
String Imagepath;
String locimage;
String loclocation;
String latlat;
String loclong;
String locdesp,TdairyID;
String Location = "'India Diary'";
String Loct;
String Alltitles;
TextView statusText;
Button Delete;
Button Bk;
private Button btnAdd;
String[] icon = new String[] { R.drawable.tdiconn + "" };
private ProgressDialog progressDialog;
String stat = "Status:";
String statContent = "Online";
String[] logos;
String[] logo = new String[] { R.drawable.logogtalk + "" };
String[] Skypelogo = new String[] { R.drawable.logoskype + "" };
String[] yahoologo = new String[] { R.drawable.logoyahoo + "" };
ListView travellist;
SimpleAdapter adapter;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.traveldiarylist);
Delete = (Button) findViewById(R.id.Del);
// Bk = (Button) findViewById(R.id.Backb);
btnAdd=(Button)findViewById(R.id.btntraveldiaryadd);
DBAdapter db = new DBAdapter(this);
db.open();
db.deleteAll();
db.close();
Delete.setOnClickListener(this);
btnAdd.setOnClickListener(this);
travellist = (ListView) findViewById(R.id.traveldiarylistview);
travellist.setItemsCanFocus(false);
String[] from = new String[] { "icon", "buddyname", "desc", "date" };
int[] to = new int[] { R.id.locationicon, R.id.locationname,
R.id.traveldesc, R.id.date };
List<HashMap<String, String>> fillMaps = TraveldairyForSimpleAdapter();// new
// ArrayList<HashMap<String,
// String>>();
adapter = new SimpleAdapter(this, fillMaps, R.layout.traveldiaryitems,
from, to) {
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
return v;
}
};
travellist.setAdapter(adapter);
travellist
.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3)
{
// for(int i=0;i<=arg2;i++ );
System.out
.println("Item clicked1 !!!!!!!!!onItemSelected");
}
public void onNothingSelected(AdapterView<?> arg0)
{
System.out
.println("Item clicked2 !!!!!!!onNothingSelected!!");
* Intent travelIntent = new Intent();
* travelIntent.setClassName("mon.ctacts",
* "mon.ctacts.TraveldairyActivity");
* //chatIntent.putExtras(bundle);
* startActivity(travelIntent);
}
});
travellist.setOnItemClickListener(listClick);
}
// protected void progress()
// {
// // TODO Auto-generated method stub
//
// progressDialog = ProgressDialog.show(this, "", "Login...");
//
// new Thread()
// {
// public void run()
// {
//
// try
// {
//
// // Thread.sleep(2000);
//
// /*
// * System.out.println("onclick Del");
// *
// * Intent myIntent = new Intent();
// * myIntent.setClassName("mon.ctacts",
// * "mon.ctacts.DelTravellistActivity");
// *
// * startActivity(myIntent);
//
//
// }
//
// catch (Exception e)
// {
//
// }
//
// }// run
//
// }.start();// new thread
//
// }// end progrss bar brakret
private List<HashMap<String, String>> TraveldairyForSimpleAdapter() {
// TODO Auto-generated method stub
String token=MontactToken.getToken();
String userid=MontactToken.getUserId();
String address="http://java.greymatterindia.com/montacts/web/mnt_dev.php/api/getTravelDiary?data=" + "%7B" +"%22NoOfRec%22" + "%3A" + "20" + "," + "%22TokenKey%22" + "%3A" + "%22"+token+"%22" + "," + "%22StartRecNo%22" + "%3A" + "%221%22" + "," + "%22UsrId%22" + "%3A" + "%22"+userid+"%22" + "," + "%22EndRecNo%22" + "%3A" + "%2220%22" + "%7D" ;
//10-15 15:33:31.804: INFO/System.out(412): urlview...........http://java.greymatterindia.com/montacts/web/mnt_dev.php/api/getTravelDiary?data=%7B%22NoOfRec%22%3A20,%22TokenKey%22%3A%22ADRWYw==%22,%22StartRecNo%22%3A%221%22,%22UsrId%22%3A%22235%22,%22EndRecNo%22%3A%2220%22%7D
System.out.println(address);
List<HashMap<String, String>> fillMaps = new ArrayList<HashMap<String, String>>();
try {
// HashMap<String, String> map = new HashMap<String, String>();
JSONObject json = montact.gmailfriends.json.montactfriends
.connect(address);
//JSONObject data = json.getJSONObject("data");
String TotalRecord = json.getString("TotalRecord");
System.out.println(TotalRecord);
//http://java.greymatterindia.com/montacts/web/mnt_dev.php/api/getTravelDiary?data={%22NoOfRec%22:20,%22TokenKey%22:%22ADRWYw==%22,%22StartRecNo%22:%221%22,%22UsrId%22:%22235%22,%22EndRecNo%22:%2220%22}
//String rcode = json.getString("rcode");
//System.out.println(rcode);
//String page = json.getString("page");
// System.out.println(page);
// String dataobject= json.getString("data");
// JSONObject dataObject = json.getJSONObject("data");
//String totalResults = dataObject.getString("totalResults");
// System.out.println(totalResults);
// JSONObject sucessObject = json.getJSONObject("totalPages");
//String totalPages = dataObject.getString("totalPages");
// System.out.println(totalPages);
* String image1 = dataObject.getString("image");
* System.out.println(image1);
// JSONObject itemObject =dataObject.getJSONObject("items");
JSONArray arrayitems = json.getJSONArray("TravelDiary");
for (int i = 0; i < arrayitems.length(); i++) {
System.out.println("count");
// String status = "";
String name = arrayitems.getJSONObject(i).getString("TrdName")
.toString();
Dname = name;
// System.out.println(name);
String image = arrayitems.getJSONObject(i).getString(
"image").toString();
Dimage = image;
// System.out.println(image);
String TrdId = arrayitems.getJSONObject(i).getString(
"TrdId").toString();
TdairyID = TrdId;
System.out.println(TrdId);
String description1 = arrayitems.getJSONObject(i).getString(
"TrdDesciption").toString();
Ddescription = description1;
// System.out.println(description1);
String Date = arrayitems.getJSONObject(i).getString(
"TrdCreateddate").toString();
Ddate = Date;
System.out.println(Ddate);
HashMap<String, String> map = new HashMap<String, String>();
map.put("icon", icon[0]);
if (name != null) {
map.put("buddyname", name);
} else {
map.put("buddyname", name);
}
if ( Ddescription != null) {
map.put("desc", Ddescription); }
else { map.put("desc", Ddescription);
}
if (Date != null) {
map.put("date", Date);
} else {
map.put("Date", Date);
}
fillMaps.add(map);
// JSONObject itemObject = json.getJSONObject("items");
// JSONObject location =
// arrayitems.getJSONObject(i).getJSONObject("location");
JSONArray arraylocations = arrayitems.getJSONObject(i)
.getJSONArray("location");
for (int z = 0; z < arraylocations.length(); z++) {
// List<HashMap<String, String>> fillLocationMap = new
// ArrayList<HashMap<String, String>>();
String lname = arraylocations.getJSONObject(z).getString(
"Name").toString();
Dlocation = lname;
// System.out.println(lname);
String locationImage = arraylocations.getJSONObject(z)
.getString("locationImage").toString();
// System.out.println(locationImage);
limages = locationImage;
String lat = arraylocations.getJSONObject(z).getString(
"lat").toString();
// System.out.println(lat);
Dlatitude = lat;
String lng = arraylocations.getJSONObject(z).getString(
"lng").toString();
Dlongitude = lng;
// System.out.println(lng);
String description = arraylocations.getJSONObject(z)
.getString("description").toString();
ldescription = description;
// System.out.println(description);
JSONArray arrayimage = arraylocations.getJSONObject(z)
.getJSONArray("images");
for (int y = 0; y < arrayimage.length(); y++) {
String imagename = arrayimage.getJSONObject(y)
.getString("Name").toString();
Imagename = imagename;
// System.out.println(imagename);
String imagepath = arrayimage.getJSONObject(y)
.getString("imagepath").toString();
Imagepath = imagepath;
// System.out.println(imagepath);
DBAdapter db = new DBAdapter(this);
db.open();
long id;
id = db.insertTitle(Dname,
Dimage,Ddescription,Ddate
,Dlocation,Dlatitude,Dlongitude,
ldescription,limages,Imagename,Imagepath);
db.close();
// ---get all titles---
db.open();
Cursor c = db.getAllTitles();
if (c.moveToFirst()) {
do {
DisplayAllTitle(c);
} while (c.moveToNext());
}
db.close();
// Delete all database
db.open();
db.deleteAll();
db.close();
}
// //---get a title---
}
}
DBAdapter db = new DBAdapter(this);
db.open();
Cursor q = db.getdistinct();
if (q.moveToFirst())
{
System.out.println("dairy location found");
do
{
// DisplayDistinct(q);
// System.out.print("\n"+ q.getString(0)+"\n");
Alltitles = q.getString(0);
System.out.print(" \n" + Alltitles + "\n");
System.out.println("particulars!!!!!!");
Location = "'" + Alltitles + "'";
Cursor c = db.getParticulardai(Location);
if (c.moveToFirst()) {
do {
locimage = c.getString(8);
loclocation = c.getString(4);
latlat = c.getString(5);
loclong = c.getString(6);
locdesp = c.getString(7);
System.out.println(locimage);
System.out.println(loclocation);
System.out.println(latlat);
System.out.println(loclong);
System.out.println(locdesp);
;
} while (c.moveToNext());
}
} while (q.moveToNext());
} else {
System.out.println(" no dairylocation found");
}
db.close();
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Size of fillMaps>>>>>>>>>>" + fillMaps.size());
// adapter.notifyDataSetChanged();
return fillMaps;
}
private void DisplayAllTitle(Cursor c)
{ // TODO Auto-generated method
// * stub
*//**
* Toast.makeText( this, "id: " + c.getString(0) + "\n" + "DAIRYNAME: "
* + c.getString(1) + "\n" + "DAIRY_IMAGE: " + c.getString(2) + "\n" +
* "DAIRY_DISCRIPTION: " + c.getString(3)+ "\n" + "DATE: " +
* c.getString(4)+ "\n" + "LOCATION_TITLE: " + c.getString(5)+ "\n" +
* "LATITUTE: " + c.getString(6)+ "\n" + "LONG: " + c.getString(7)+
* "\n" + "LOCATION_DESCRIPTION: " + c.getString(8)+ "\n" +
* "LOCATON_IMAGE: " + c.getString(9)+ "\n" + "IMAGE_NAME: " +
* c.getString(10)+ "\n" + "IMAGEPATH: " + c.getString(11),
* Toast.LENGTH_LONG) .show();
*//*
System.out.println("id: " + c.getString(0) + "\n" + "DAIRYNAME: "
+ c.getString(1) + "\n" + "DAIRY_IMAGE: " + c.getString(2)
+ "\n" + "DAIRY_DISCRIPTION: " + c.getString(3) + "\n"
+ "DATE: " + c.getString(4) + "\n" + "LOCATION_TITLE: "
+ c.getString(5) + "\n" + "LATITUTE: " + c.getString(6) + "\n"
+ "LONG: " + c.getString(7) + "\n" + "LOCATION_DESCRIPTION: "
+ c.getString(8) + "\n" + "LOCATON_IMAGE: " + c.getString(9)
+ "\n" + "IMAGE_NAME: " + c.getString(10) + "\n"
+ "IMAGEPATH: " + c.getString(11));
// Alltitles=c.getString(1);
// System.out.println(Alltitles);
}
AdapterView.OnItemClickListener listClick = new OnItemClickListener()
{
@SuppressWarnings("unchecked")
public void onItemClick(AdapterView parent, View view, int position,long id)
{
HashMap<String, String> temp = (HashMap<String, String>) parent
.getItemAtPosition(position);
String username = temp.get("buddyname").toString();
// Bundle bun=new Bundle();
// bun.putParcelableArrayList(key, value);
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!");
System.out.println(username);
Bundle bundle = new Bundle();
bundle.putString("buddyName", username);
Intent locIntent = new Intent();
// chatIntent.setClassName("mon.ctacts", "mon.ctacts.StartChat");
locIntent.setClassName("mon.ctacts",
"mon.ctacts.TraveldairyActivity");
locIntent.putExtras(bundle);
startActivity(locIntent);
}
};
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
// Handle item selection
switch (item.getItemId())
{
case R.id.logout:
return true;
case R.id.setting:
Intent intent = new Intent(TravellistActivity.this,
SettingPage.class);
startActivity(intent);
return true;
case R.id.exit:
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public void onClick(View v)
{
// TODO Auto-generated method stub
if ((Button) v == Delete)
{
//progress();
progressDialog = ProgressDialog.show(this, "", "Loading...");
new Thread()
{
public void run()
{
try
{
Thread.sleep(2000);
System.out.println("onclick Del");
progressDialog.dismiss();
Intent myIntent = new Intent();
myIntent.setClassName("mon.ctacts",
"mon.ctacts.DelTravellistActivity");
startActivity(myIntent);
}
catch (Exception e)
{
}
}// run
}.start();// new thread
}
if((Button)v==btnAdd)
{
Intent myIntent = new Intent();
myIntent.setClassName("mon.ctacts",
"mon.ctacts.TravelDiaryNewActivity");
startActivity(myIntent);
}
}
* @Override public void onClick(View v) { // TODO Auto-generated method
* stub if ((Button) v == editBtn) {
* System.out.println("Item clicked4 !!!!!!!!!onItemSelected");
*
* new Thread() { public void run() {
*
* try {
*
* Thread.sleep(2000);
*
* Intent Editintent = new Intent(); Editintent.setClassName("mon.ctacts",
* "mon.ctacts.mnlogin");
*
* startActivity(Editintent); // progressDialog.dismiss();
*
* }
*
* catch (Exception e) {
*
* }
*
* }// run
*
* }.start();// new thread
*
* }// end progrss bar brakret
*
* }
* public String download(String url) { URL ImageUrl = null ; try { ImageUrl
* = new URL(url); URLConnection urlConnection = ImageUrl.openConnection();
*
* File imageFile = new File("/sdcard/icon.jpg");
*
* InputStream is = urlConnection.getInputStream(); BufferedInputStream bis
* = new BufferedInputStream(is);
*
* FileOutputStream fos = new FileOutputStream(imageFile); int tempByte;
* StringBuffer sb = new StringBuffer();
*
* while ((tempByte = bis.read()) != -1) { sb.append((char) tempByte);
* fos.write(tempByte);
*
* }
*
* this.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri
* .parse("file://" + Environment.getExternalStorageDirectory())));
*
* } catch (MalformedURLException e) { // TODO Auto-generated catch block
* e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated
* catch block e.printStackTrace();
*
* }
*
* return ImageUrl.getPath(); }
// 375011049
}
*/
No comments:
Post a Comment