I have a listview with checkbox in each row,the items is not displaying in listview , only checkbox is displayling if i select the single checkbox means two checkboxes getting selected. i need single checkbox should checked.
public class VisitingPlaces_FliterList extends Activity {
String strUrl;
JSONArray places = null;
private static String url = "http://ift.tt/1IK1EM9";
private static String url1 = "http://ift.tt/1WlCqe8";
TourGuideController dbcon;
String data;
private static final String TAG_PLACES = "PLACES";
private static final String TAG_NAME = "place_name";
TextView msg;
ListView mListView;
private ProgressDialog pDialog;
HashMap<String, Object> hm = null;
HashMap<String, Object> hm2 = null;
HashMap<String, Object> hm3 = null;
VisitingPlaces_Getter obj;
ArrayList<HashMap<String, String>> placeList;
AutoCompleteTextView desigination,source11 ;
AutoCompleteTextView source;
final Context context = this;
List<String> responseList = new ArrayList<String>();
SimpleAdapter adapter;
Button click,delete;
String location;
String src1 ;
String desc1 ;
long count1;
CheckBox placeselect;
Map<String, VisitingPlaces_Getter> visitings = null;
ArrayList<Map<String, Object>> newList = null;
LayoutInflater inflater;
@Override
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.visitingplace_fliterlist);
click = (Button) findViewById(R.id.start_plan);
delete = (Button) findViewById(R.id.delete);
dbcon = new TourGuideController(this);
dbcon.open();
inflater=(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Cursor cursor = dbcon.readAll();
Log.v("Cursor Object", DatabaseUtils.dumpCursorToString(cursor));
new GetSpinner().execute();
click.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
dbcon.deleteData();
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
VisitingPlaces_FliterList.this,
android.R.layout.simple_dropdown_item_1line, responseList);
LayoutInflater li = LayoutInflater.from(context);
View promptsView = li.inflate(R.layout.prompts, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
alertDialogBuilder.setView(promptsView);
source = (AutoCompleteTextView) promptsView.findViewById(R.id.source);
desigination = (AutoCompleteTextView) promptsView.findViewById(R.id.desigination);
source.setAdapter(arrayAdapter);
desigination.setAdapter(arrayAdapter);
alertDialogBuilder
.setCancelable(false)
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
String src = source.getText().toString();
String desc = desigination.getText().toString();
System.out.println("TESTING SRC>>>>>"+src);
System.out.println("TESTING DESC>>>>>"+desc);
SendHttpRequestTask t = new SendHttpRequestTask();
String[] params = new String[]{url1, src,desc};
t.execute(params);
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
dialog.cancel();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
});
msg = (TextView)findViewById(R.id.msg);
strUrl = "http://ift.tt/1WlCqe8";
}
private class SendHttpRequestTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
String url1 = params[0];
final String src1 = params[1];
final String desc1 = params[2];
try {
HttpClient client = new HttpClient(url1);
client.connectForMultipart();
client.addFormPart("parseSource", src1);
client.addFormPart("parseDestination", desc1);
client.finishMultipart();
data = client.getResponse();
if(data!=null){
Handler h = new Handler(Looper.getMainLooper());
h.post(new Runnable() {
public void run() {
DownloadTask downloadTask = new DownloadTask();
downloadTask.execute(strUrl);
mListView = (ListView) findViewById(R.id.list_visit);
}
});
}
else{
Toast.makeText(getBaseContext(), "no data", Toast.LENGTH_SHORT).show();
}
System.out.println("SORTED RESPONSE"+data);
}
catch(Throwable t) {
t.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String data) {
}
}
private class GetSpinner extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(VisitingPlaces_FliterList.this);
pDialog.setMessage("Please wait...");
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected Void doInBackground(Void... arg0) {
ServiceHandler sh = new ServiceHandler();
String jsonStr = sh.makeServiceCall(url, ServiceHandler.GET);
Log.d("Spinner Response: ", "> " + jsonStr);
if (jsonStr != null) {
try {
JSONObject jsonObj = new JSONObject(jsonStr);
places = jsonObj.getJSONArray(TAG_PLACES);
for (int i = 0; i < places.length(); i++) {
final JSONObject e = places.getJSONObject(i);
String name = e.getString(TAG_NAME);
responseList.add(name);
}
} catch (JSONException e) {
e.printStackTrace();
}
} else {
Log.e("ServiceHandler", "Couldn't get any data from the url");
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
// Dismiss the progress dialog
if (pDialog.isShowing())
pDialog.dismiss();
}
}
private class DownloadTask extends AsyncTask<String, Integer, String>{
//String data = null;
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(VisitingPlaces_FliterList.this);
//pDialog.setIndeterminateDrawable(getResources().getDrawable(R.anim.progress));
pDialog.setMessage("Please wait...");
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected String doInBackground(String... url) {
try{
//data = downloadUrl(url[0]);
Log.e("LISTVIEW RESPONSE", data);
}catch(Exception e){
Log.d("Background Task",e.toString());
}
return data;
}
@Override
protected void onPostExecute(String result) {
if (pDialog.isShowing())
pDialog.dismiss();
ListViewLoaderTask listViewLoaderTask = new ListViewLoaderTask();
listViewLoaderTask.execute(result);
}
}
private Bitmap decodeFile(File f) {
try {
// Decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream(new FileInputStream(f), null, o);
// The new size we want to scale to
final int REQUIRED_SIZE=70;
// Find the correct scale value. It should be the power of 2.
int scale = 1;
while(o.outWidth / scale / 2 >= REQUIRED_SIZE &&
o.outHeight / scale / 2 >= REQUIRED_SIZE) {
scale *= 2;
}
// Decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
} catch (FileNotFoundException e) {}
return null;
}
private class ListViewLoaderTask extends AsyncTask<String, Void, SimpleAdapter>{
JSONObject jObject;
@Override
protected SimpleAdapter doInBackground(String... strJson) {
try{
jObject = new JSONObject(strJson[0]);
Visting_PlacesJSONParser visitingJsonParser = new Visting_PlacesJSONParser();
visitingJsonParser.parse(jObject);
}catch(Exception e){
Log.d("JSON Exception1",e.toString());
}
Visting_PlacesJSONParser visitingJsonParser = new Visting_PlacesJSONParser();
List<String> imgList = null;
try{
visitings = visitingJsonParser.parse(jObject);
Log.e("jObject", jObject.toString());
Map<String, Object> test=null;
if(visitings.size() >0){
newList = new ArrayList<Map<String,Object>>();
for (Map.Entry<String, VisitingPlaces_Getter> entry : visitings.entrySet())
{
test =new HashMap<String, Object>();
obj=(VisitingPlaces_Getter)entry.getValue();
test.put("place_id", obj.getPlace_id());
test.put("place_name", obj.getPlace_name());
test.put("place_image", obj.getPlace_image());
test.put("place_description", obj.getDescription());
test.put("flag", R.drawable.defailt_profile_img);
test.put("place_rating", obj.getRating());
test.put("place_check", "true");
String p_id = obj.getPlace_id();
String p_name = obj.getPlace_name();
String p_rating = obj.getRating();
String p_description = obj.getDescription();
//String p_id = obj.getPlace_id();
System.out.println("p_id"+p_id);
System.out.println("p_name"+p_name);
System.out.println("p_rating"+p_rating);
System.out.println("p_description"+p_description);
newList.add(test);
dbcon.insertData(p_id, p_name, p_rating, p_description);
}
}
else{
msg.setVisibility(View.VISIBLE);
}
}catch(Exception e){
Log.d("Exception",e.toString());
}
adapter = new SimpleAdapter(getBaseContext(), newList, R.layout.visitingplace_backfliter, new String[]{ "place_name","flag","place_rating","place_description"},new int[]{ R.id.tv_title, R.id.iv_flag,R.id.ratingBar2,R.id.tv_desc})
{
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = inflater.inflate(R.layout.visitingplace_backfliter, null);
}
placeselect = (CheckBox) convertView.findViewById(R.id.select_place);
placeselect .setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (placeselect.isChecked()){
// adapter = new SimpleAdapter(getBaseContext(), newList, R.layout.visitingplace_backfliter,from,to);
Toast.makeText(VisitingPlaces_FliterList.this, "TEST", Toast.LENGTH_SHORT).show();
Log.e("testnnn", "testnnn");
}
}
});
return convertView;
}
};
// adapter = new SimpleAdapter(getBaseContext(), newList, R.layout.visitingplace_backfliter,from,to);
adapter.setViewBinder(new MyBinder());
return adapter;
}
@Override
protected void onPostExecute(final SimpleAdapter adapter) {
if (pDialog.isShowing())
pDialog.dismiss();
mListView.setAdapter(adapter);
// mListView.setAdapter(new ImageAdapter(VisitingPlaces_FliterList.this));
for(int i=0;i<adapter.getCount();i++){
hm = (HashMap<String, Object>) adapter.getItem(i);
String imgUrl = (String) hm.get("place_image");
ImageLoaderTask imageLoaderTask = new ImageLoaderTask();
HashMap<String, Object> hmDownload = new HashMap<String, Object>();
hm.put("place_image",imgUrl);
hm.put("position", i);
// Starting ImageLoaderTask to download and populate image in the listview
imageLoaderTask.execute(hm);
mListView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
//Toast.makeText(VisitingPlaces_FliterList.this, "test", Toast.LENGTH_SHORT).show();
hm2 = (HashMap<String, Object>) adapter.getItem(position);
ArrayList<String> arr = new ArrayList<String>();
System.out.println("postion"+hm2);
String name = (String) hm2.get("place_name");
String description = (String) hm2.get("place_description");
String image_path = (String) hm2.get("place_image");
System.out.println("description_testing"+description);
Intent in = new Intent(VisitingPlaces_FliterList.this,VisitingPlaces_Detailedview.class);
in.putExtra("place_name", name);
in.putExtra("place_description", description);
in.putExtra("imagePath", image_path);
//in.putExtra("title", visiting_title);
//in.putExtra("desc",description);
//Toast.makeText(VisitingPlaces_FliterList.this, "test", Toast.LENGTH_SHORT).show();
startActivity(in);
}
});
}
}
}
class MyBinder implements ViewBinder{
public boolean setViewValue(View view, Object data, String rate) {
if(view.getId() == R.id.ratingBar2){
String stringval = rate;
float ratingValue = Float.parseFloat(stringval);
RatingBar ratingBar = (RatingBar) view;
ratingBar.setRating(ratingValue);
return true;
}
return false;
}
}
private class ImageLoaderTask extends AsyncTask<HashMap<String, Object>, Void, HashMap<String, Object>>{
@Override
protected HashMap<String, Object> doInBackground(HashMap<String, Object>... hm) {
InputStream iStream=null;
String imgUrl = (String) hm[0].get("place_image");
int position = (Integer) hm[0].get("position");
URL url;
try {
url = new URL(imgUrl);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.connect();
iStream = urlConnection.getInputStream();
File cacheDirectory = getBaseContext().getCacheDir();
File tmpFile = new File(cacheDirectory.getPath() + "/visiting_"+position+".png");
System.out.println("TEMPFILE"+tmpFile);
FileOutputStream fOutStream = new FileOutputStream(tmpFile);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 8;
Bitmap preview_bitmap = BitmapFactory.decodeStream(iStream, null, options);
//Bitmap b = BitmapFactory.decodeStream(iStream);
preview_bitmap.compress(Bitmap.CompressFormat.PNG,100, fOutStream);
fOutStream.flush();
fOutStream.close();
HashMap<String, Object> hmBitmap = new HashMap<String, Object>();
hmBitmap.put("flag",tmpFile.getPath());
hmBitmap.put("position",position);
return hmBitmap;
}catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(HashMap<String, Object> result) {
String path = (String) result.get("flag");
int position = (Integer) result.get("position");
SimpleAdapter adapter = (SimpleAdapter ) mListView.getAdapter();
HashMap<String, Object> hm = (HashMap<String, Object>) adapter.getItem(position);
hm.put("flag",path);
adapter.notifyDataSetChanged();
if (pDialog.isShowing())
pDialog.dismiss();
}
}
}
Aucun commentaire:
Enregistrer un commentaire