1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
| package com.aziz.bdk.applimvcv2;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
public class SingleItemActivity extends Activity implements ParsingListener{
private static final String urldescentreprises = "http://91.121.26.112/lucas/jsongoogledetail.txt";
private static final String TAG_DESCRIPTION = "description";
private static final String TAG_ID = "id";
private static final String TAG_TITLE = "title";
private static final String TAG_AVATAR = "avatar";
private static final String TAG_DESCRIPTIONA = "descriptionA";
private static final String TAG_CONTRACT = "contract";
private static final String TAG_CATEGORY = "category";
private static final String TAG_CITY = "city";
private TextView companyTV;
private TextView cityTV;
private TextView registering_dateTV;
private TextView number_of_employeeTV;
private TextView categoryTV;
private TextView urlTV;
private TextView saTV;
private ListView lv;
private JParse jParse;
private String numid;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.singleactivity_main);
Intent in = getIntent();
numid = in.getStringExtra(TAG_ID);
jParse = new JParse(urldescentreprises, this);
jParse.execute();
}
public void parsingComplete() {
Entreprise entreprise = Entreprise.getEntreprise(jParse);
companyTV = (TextView) findViewById(R.id.company2);
companyTV.setText(entreprise.getCompany());
cityTV = (TextView) findViewById(R.id.city2);
cityTV.setText(entreprise.getCity());
registering_dateTV = (TextView) findViewById(R.id.registering_date);
registering_dateTV.setText(entreprise.getRegistering_date());
number_of_employeeTV = (TextView) findViewById(R.id.number_of_employee);
number_of_employeeTV.setText(entreprise.getNumber_of_employee());
categoryTV = (TextView) findViewById(R.id.category);
categoryTV.setText(entreprise.getCategory());
urlTV = (TextView) findViewById(R.id.url);
urlTV.setText(entreprise.getUrl());
saTV = (TextView) findViewById(R.id.sa);
saTV.setText(entreprise.getSa());
String description = entreprise.getDescription();
String idA = entreprise.getIdA();
String title = entreprise.getTitle();
String avatar = entreprise.getAvatar();
String descriptionA = entreprise.getDescriptionA();
String contract = entreprise.getContract();
String categoryA = entreprise.getCategoryA();
String cityA = entreprise.getCityA();
lv = (ListView) findViewById(R.id.metaslv);
ArrayList<HashMap<String, String>> metasList = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_DESCRIPTION, description);
map.put(TAG_ID, idA);
map.put(TAG_TITLE, title);
map.put(TAG_AVATAR, avatar);
map.put(TAG_DESCRIPTIONA, descriptionA);
map.put(TAG_CONTRACT, contract);
map.put(TAG_CATEGORY, categoryA);
map.put(TAG_CITY, cityA);
metasList.add(map);
if(entreprise.getIdA2()!=null)
{
String idA2 = entreprise.getIdA2();
String title2 = entreprise.getTitle2();
String avatar2 = entreprise.getAvatar2();
String descriptionA2 = entreprise.getDescriptionA2();
String contract2 = entreprise.getContract2();
String categoryA2 = entreprise.getCategoryA2();
String cityA2 = entreprise.getCityA2();
HashMap<String, String> map2 = new HashMap<String, String>();
map2.put(TAG_ID, idA2);
map2.put(TAG_TITLE, title2);
map2.put(TAG_AVATAR, avatar2);
map2.put(TAG_DESCRIPTIONA, descriptionA2);
map2.put(TAG_CONTRACT, contract2);
map2.put(TAG_CATEGORY, categoryA2);
map2.put(TAG_CITY, cityA2);
metasList.add(map);
if(entreprise.getIdA3()!=null)
{
String idA3 = entreprise.getIdA3();
String title3 = entreprise.getTitle3();
String avatar3 = entreprise.getAvatar3();
String descriptionA3 = entreprise.getDescriptionA3();
String contract3 = entreprise.getContract3();
String categoryA3 = entreprise.getCategoryA3();
String cityA3 = entreprise.getCityA3();
HashMap<String, String> map3 = new HashMap<String, String>();
map3.put(TAG_ID, idA3);
map3.put(TAG_TITLE, title3);
map3.put(TAG_AVATAR, avatar3);
map3.put(TAG_DESCRIPTIONA, descriptionA3);
map3.put(TAG_CONTRACT, contract3);
map3.put(TAG_CATEGORY, categoryA3);
map3.put(TAG_CITY, cityA3);
metasList.add(map);
}
}
ListAdapter adapter2 = new SimpleAdapter(SingleItemActivity.this, metasList, R.layout.list_metas, new String[]{TAG_DESCRIPTION, TAG_TITLE, TAG_AVATAR, TAG_DESCRIPTIONA, TAG_CONTRACT, TAG_CATEGORY, TAG_CITY}, new int[]{R.id.description2, R.id.title, R.id.avatar, R.id.description3, R.id.contract, R.id.category2, R.id.city3});
lv.setAdapter(adapter2);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
HashMap<String, String> map = (HashMap<String, String>) parent.getItemAtPosition(position);
JSONObject selectedObject = new JSONObject(map);
try {
String identifiant = selectedObject.getString(TAG_ID);
Intent in = new Intent(getApplicationContext(), AnnonceDetailsActivity.class);
in.putExtra(TAG_ID, identifiant);
startActivity(in);
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
} |