How to use Fragment in Android? - android

iam using menu slidding, this code for call other class
}else if (id == R.id.list) {
//Set the fragment initially
StockProduct fragment = new StockProduct();
android.support.v4.app.FragmentTransaction fragmentTransaction =
getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment);
fragmentTransaction.commit();
}
but fragment error i don't know why...
and this is my class code
public class StockProduct extends Fragment implements ListView.OnItemClickListener {
String myJSON;
private static final String TAG_RESULTS = "result";
private static final String TAG_NAME = "name_product";
private static final String TAG_ID = "product_id";
JSONArray peoples = null;
ArrayList<HashMap<String, String>> personList;
ListView list;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.list_product, container, false);
list = (ListView) view.findViewById(R.id.allproduct);
personList = new ArrayList<HashMap<String, String>>();
getData();
return view;
}
public void getData() {
class GetDataJSON extends AsyncTask<String, Void, String> {
#Override
protected String doInBackground(String... params) {
DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams());
HttpPost httppost = new HttpPost(Config.ALLPRODUCT_URL);
// Depends on your web service
httppost.setHeader("Content-type", "application/json");
InputStream inputStream = null;
String result = null;
try {
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
inputStream = entity.getContent();
// json is UTF-8 by default
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
result = sb.toString();
} catch (Exception e) {
// Oops
}
finally {
try{if(inputStream != null)inputStream.close();}catch(Exception squish){}
}
return result;
}
}
}
protected void showList(){
try {
JSONObject jsonObj = new JSONObject(myJSON);
peoples = jsonObj.getJSONArray(TAG_RESULTS);
for(int i=0;i<peoples.length();i++){
JSONObject c = peoples.getJSONObject(i);
String id = c.getString(TAG_ID);
String name = c.getString(TAG_NAME);
HashMap<String,String> persons = new HashMap<String,String>();
persons.put(TAG_ID, id);
persons.put(TAG_NAME, name);
personList.add(persons);
}
ListAdapter adapter = new SimpleAdapter(
StockProduct.this.getActivity(), personList, R.layout.list_product_component,
new String[]{TAG_ID,TAG_NAME},
new int[]{R.id.idproduct, R.id.nameproduct}
);
list.setAdapter(adapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(this.getActivity(), StockProductView.class);
HashMap<String,String> map =(HashMap)parent.getItemAtPosition(position);
String product_id = map.get(TAG_ID).toString();
intent.putExtra(Config.TAG_PRODUCT_ID,product_id);
startActivity(intent);
}}
and this is log error

Try replacing this line,
StockProduct fragment = new StockProduct();
with
Fragment fragment = new StockProduct();
Make sure all your import statements import support fragment

Related

Vertical Progress Bar on Android

I want to implement progress bar on list view for data that am getting from Mysql server here is my code any new suggestion are welcome for an example change your layout or anything which will make implementation easy as am neophyte
public class teststatusActivity extends BaseActivity {
String myJSON = "" ;
private static final String TAG_RESULTS = "result";
private static final String TAG_TICKET = "ticket_id";
private static final String TAG_Status = "ticket_status";
private static final String TAG_Status1 = "ticket_status1";
private static final String TAG_Status2 = "ticket_status2";
private static final String TAG_Status3 = "ticket_status3";
private static final String TAG_I = "";
public static final String DATA_URL = "http://103.3.62.23/complain_dashboard/api/getTicketStatus.php?ticket_id=";
public String ticketID;
JSONArray peoples = null;
ListView list;
ArrayList<HashMap<String, String>> usersList;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_teststatus);
list = (ListView) findViewById(R.id.listView);
usersList = new ArrayList<HashMap<String, String>>();
getData();
}
protected void showList() {
try {
JSONObject jsonObj = new JSONObject(myJSON);
JSONObject pe = jsonObj.getJSONObject(TAG_RESULTS);
String id = pe.getString("ticket_id");
String status = pe.getString("ticket_status");
String stat = null;
String stat1 = null;
String stat2 = null;
String stat3 = null;
if (pe.get("ticket_status").equals("0")) {
stat = "Feedback Sent To Team";
}
if (pe.get("ticket_status").equals("1")) {
stat1 = "Technical Team is Working on it";
}
if (pe.get("ticket_status").equals("2")) {
stat2 = "Your Report is About To Resolve";
}
if (pe.get("ticket_status").equals("3")) {
stat3 = "Resolved";
}
HashMap<String, String> users = new HashMap<String, String>();
users.put( TAG_TICKET , id );
users.put(TAG_Status, stat );
users.put(TAG_Status1, stat1 );
users.put(TAG_Status2, stat2);
users.put(TAG_Status3, stat3);
usersList.add(users);
ListAdapter adapter = new SimpleAdapter(
teststatusActivity.this, usersList, R.layout.list_item,
new String[]{TAG_TICKET, TAG_Status,TAG_Status1, TAG_Status2, TAG_Status3 },
new int[]{R.id.feed, R.id.feedS, R.id.feedwork, R.id.abouttoresolve, R.id.resolved}
);
list.setAdapter(adapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
public void getData() {
class GetDataJSON extends AsyncTask<String, Void, String> {
SharedPreferences sharedPref = getSharedPreferences("tcktid", Context.MODE_WORLD_READABLE);
final String ticket =sharedPref.getString("tid", null);
#Override
protected String doInBackground(String... params) {
DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams());
HttpPost httppost = new HttpPost(DATA_URL + ticket);
// Depends on your web service
httppost.setHeader("Content-type", "application/json");
InputStream inputStream = null;
String result = null;
try {
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
inputStream = entity.getContent();
// json is UTF-8 by default
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
result = sb.toString();
} catch (Exception e) {
} finally {
try {
if (inputStream != null) inputStream.close();
} catch (Exception squish) {
}
}
return result;
}
#Override
protected void onPostExecute(String result) {
myJSON = result;
showList();
}
}
GetDataJSON g = new GetDataJSON();
g.execute();
}
} ;

Button click action not working in android listview

I am developing an android app which functions like as follows
Admin creates the data and saves it into database then user access the same data through app when it comes down to showing the data to user i fetch the data from the database which admin has already saved i show the data in listview, and listview having buttons in each row when user click on button it dose not goes to next activity.When user will click on button in listview the activity should pass to next activity.How do i do this?
//java activity
public class MainActivity extends ActionBarActivity {
String myJSON;
SimpleAdapter adapter;
Button btn;
private static final String TAG_RESULTS = "result";
private static final String TAG_NAME = "sname";
private static final String TAG_PRICE = "sprice";
JSONArray peoples = null;
ArrayList<HashMap<String, String>> personList;
// ArrayList<HashMap<String, String>> personList = new ArrayList<HashMap<String, String>>();
ListView list, listView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list = (ListView) findViewById(R.id.listView_search);
btn = (Button) findViewById(R.id.button3_book);
personList = new ArrayList<HashMap<String, String>>();
getData();
// Listview on item click listener
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent zoom=new Intent(parent.getContext(), Details.class);
parent.getContext().startActivity(zoom);
}
});
}
protected void showList(){
try {
JSONObject jsonObj = new JSONObject(myJSON);
peoples = jsonObj.getJSONArray(TAG_RESULTS);
for(int i=0;i<peoples.length();i++){
JSONObject c = peoples.getJSONObject(i);
String sname = c.getString(TAG_NAME);
String sprice = c.getString(TAG_PRICE);
HashMap<String,String> persons = new HashMap<String,String>();
persons.put(TAG_NAME,sname);
persons.put(TAG_PRICE,sprice);
personList.add(persons);
}
ListAdapter adapter = new SimpleAdapter(
MainActivity.this, personList, R.layout.search_item,
new String[]{TAG_NAME,TAG_PRICE},
new int[]{ R.id.textView8_sellernm, R.id.textView19_bprice}
);
list.setAdapter(adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent i=new Intent(MainActivity.this,Details.class);
startActivity(i);
}
});
} catch (JSONException e) {
e.printStackTrace();
}
}
public void getData(){
class GetDataJSON extends AsyncTask<String, Void, String> {
#Override
protected String doInBackground(String... params) {
DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams());
HttpPost httppost = new HttpPost("http://example.com/User/reg/listview.php");
// Depends on your web service
httppost.setHeader("Content-type", "application/json");
InputStream inputStream = null;
String result = null;
try {
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
inputStream = entity.getContent();
// json is UTF-8 by default
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
result = sb.toString();
} catch (Exception e) {
// Oops
}
finally {
try{if(inputStream != null)inputStream.close();}catch(Exception squish){}
}
return result;
}
#Override
protected void onPostExecute(String result){
myJSON=result;
showList();
}
}
GetDataJSON g = new GetDataJSON();
g.execute();
}
}

How to refresh listview items once list items are updated - to be used in onResume

I have an update fragment using which i will update data in my database. Once the update is done i move back to 'view the data from database' fragment and i need the list to be updated. I think i have to write code for this inside onResume() but i don't know how to do it.
Code for 'view the data from database' fragment:
public class Testing extends Fragment {
String uname="921312104053";
private static final String TAG_RESULTS="result";
private static final String TAG_Sname = "Subject_name";
private static final String TAG_Scode = "Subject_code";
private static final String TAG_Sgrade ="Grade";
ListView lv;
JSONArray subjects = null;
String myJSON;
ListAdapter adapter;
ArrayList<HashMap<String, String>> subList,subList1;
public Testing() {
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_testing,
container, false);
disp(view);
return view;
}
public void disp(View view)
{
lv = (ListView)view.findViewById(R.id.list);
subList = new ArrayList<HashMap<String,String>>();
getData(view);
}
public void getData(View view){
class GetDataJSON extends AsyncTask<String, Void, String> {
#Override
protected String doInBackground(String... params) {
DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams());
HttpPost httppost = new HttpPost("http://10.0.2.2/markolepsy/android_connect/testing.php?usrname="+uname);
httppost.setHeader("Content-type", "application/json");
InputStream inputStream = null;
String result = null;
try {
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
inputStream = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
result = sb.toString();
} catch (Exception e) {
}
finally {
try{if(inputStream != null)inputStream.close();}catch(Exception squish){}
}
return result;
}
#Override
protected void onPostExecute(String result){
myJSON=result;
showList();
}
}
GetDataJSON g = new GetDataJSON();
g.execute();
}
protected void showList(){
try {
JSONObject jsonObj = new JSONObject(myJSON);
subjects = jsonObj.getJSONArray(TAG_RESULTS);
for(int i=0;i<subjects.length();i++){
JSONObject c = subjects.getJSONObject(i);
String sname = c.getString(TAG_Sname);
String scode = c.getString(TAG_Scode);
String sgrade = c.getString(TAG_Sgrade);
HashMap<String,String> records = new HashMap<String,String>();
records.put(TAG_Sname,sname);
records.put(TAG_Scode,scode);
records.put(TAG_Sgrade,sgrade);
subList.add(records);
}
adapter = new SimpleAdapter(
getActivity(), subList, R.layout.list_layout,
new String[]{TAG_Sname,TAG_Scode,TAG_Sgrade},
new int[]{R.id.subject_name, R.id.subject_code, R.id.grade}
);
lv.setAdapter(adapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
Using notifyDataSetChanged() may suite your needs.
Refer to this: How to refresh Android listview?
Edit:
adapter = new SimpleAdapter(
getActivity(), subList, R.layout.list_layout,
new String[]{TAG_Sname,TAG_Scode,TAG_Sgrade},
new int[]{R.id.subject_name, R.id.subject_code, R.id.grade}
);
lv.setAdapter(adapter);
adapter.notifyDataSetChanged();
The above code should help.

Fetch data from database to android list view

Im creating an android app where in im going to fetch datas such as image and text from mysql database. I have a problem with it. When i run the program, nothing was display in my listview.
Here's my City.java
public class City extends ActionBarActivity {
String myJSON;
ImageView image;
TextView name,id,description;
private static final String TAG_RESULTS="result";
public static final String TAG_ID = "place_id";
public static final String TAG_NAME = "place_name";
public static final String TAG_ADD ="description";
//public static final String TAG_PIC ="place_icture";
JSONArray cities = null;
ArrayList<HashMap<String, String>> CitiesList;
UserLocalStore userLocalStore;
ListView list;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.citylayout);
userLocalStore = new UserLocalStore(this);
name=(TextView)findViewById(R.id.name);
id=(TextView)findViewById(R.id.id);
description=(TextView)findViewById(R.id.description);
list = (ListView) findViewById(R.id.listView1);
CitiesList = new ArrayList<HashMap<String, String>>();
image = (ImageView)findViewById(R.id.image);
getData();
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(City.this, "Opening", Toast.LENGTH_LONG).show();
Map<String, Object> map = (Map<String, Object>)parent.getItemAtPosition(position);
String info1 = (String) map.get("place_id");
String info2 = (String) map.get("place_name");
String info3 = (String) map.get("description");
//String info4 = (String) map.get("place_picture");
Intent myIntent = new Intent(view.getContext(), Login.class);
myIntent.putExtra("info1", info1);
myIntent.putExtra("info2", info2);
myIntent.putExtra("info3", info3);
//myIntent.putExtra("info4", info4);
startActivity(myIntent);
}
});
}
protected void showList(){
try {
JSONObject jsonObj = new JSONObject(myJSON);
cities = jsonObj.getJSONArray(TAG_RESULTS);
for(int i=0;i<cities.length();i++){
JSONObject c = cities.getJSONObject(i);
String id = c.getString(TAG_ID);
String name = c.getString(TAG_NAME);
String address = c.getString(TAG_ADD);
//String picture = c.getString(TAG_PIC);
HashMap<String,String> persons = new HashMap<String, String>();
persons.put(TAG_ID,id);
persons.put(TAG_NAME,name);
persons.put(TAG_ADD,address);
//persons.put(TAG_PIC,picture);
CitiesList.add(persons);
}
ListAdapter adapter = new SimpleAdapter(
City.this, CitiesList, R.layout.city,
new String[]{TAG_ID,TAG_NAME,TAG_ADD},
new int[]{R.id.id,R.id.name, R.id.description}
);
list.setAdapter(adapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
public void getData(){
class GetDataJSON extends AsyncTask<String, Void, String> {
#Override
protected String doInBackground(String... params) {
DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams());
HttpPost httppost = new HttpPost("http://iguideph-001-site1.btempurl.com/city_info.php");
// Depends on your web service
httppost.setHeader("Content-type", "application/json");
InputStream inputStream = null;
String result = null;
try {
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
inputStream = entity.getContent();
// json is UTF-8 by default
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
result = sb.toString();
} catch (Exception e) {
// Oops
}
finally {
try{if(inputStream != null)inputStream.close();}catch(Exception squish){}
}
return result;
}
#Override
protected void onPostExecute(String result){
myJSON=result;
showList();
}
}
GetDataJSON g = new GetDataJSON();
g.execute();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Please change:
public static final String TAG_PIC ="place_icture";
to
public static final String TAG_PIC ="place_picture";
in the declaration.
and
persons.put(TAG_PIC,picture);
to
persons.put(TAG_PIC,String.valueOf(d));
in showList()
Hope this helps!

How implement search dialog on ListView MySql -Android

I'm practising with some tutorials I found on the web, I am communicating with a database for a listing, the unfold in a listview listview adapter as show you various names, I would like to add a search dialog, something like this Example Image but no where in the deploy, I have tried in various ways.
this is part of the code example:
LIST ACTIVITY:
public class List extends Activity {
private ProgressDialog pDialog;
public int i = 0;
JSONParser jParser = new JSONParser();
ArrayList<HashMap<String, String>> DaftarRS = new ArrayList<HashMap<String, String>>();
private static String url_daftar_rs = "my_url";
public static final String TAG_SUCCESS = "success";
public static final String TAG_DAFTAR_RS = "daftar_rs";
public static final String TAG_ID_RS = "id_rs";
public static final String TAG_NAMA_RS = "nama_rs";
public static final String TAG_LINK_IMAGE_RS = "link_image_rs";
public static final String TAG_ALAMA_RS = "alamat_rs";
public static final String TAG_TELEPONS_RS = "telepon_rs";
JSONArray daftar_rs = null;
ListView list;
ListAdapter adapter;
private ListadoActivity activity;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
DaftarRS = new ArrayList<HashMap<String, String>>();
new Activity().execute();
activity = this;
list = (ListView) findViewById(R.id.list);
list.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String id_rs = ((TextView) view
.findViewById(R.id.id_rs)).getText().toString();
Intent in = new Intent(getApplicationContext(),
DetallesActivity.class);
in.putExtra(TAG_ID_RS, id_rs);
startActivityForResult(in, 100);
}
});
}
public void SetListViewAdapter(ArrayList<HashMap<String, String>> daftar) {
adapter = new ListAdapter(activity, daftar);
list.setAdapter(adapter);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == 100) {
Intent intent = getIntent();
finish();
startActivity(intent);
}
}
class Activity extends AsyncTask<String, String, String> {
#Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(List.this);
pDialog.setMessage("wait..");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
protected String doInBackground(String... args) {
Conexion();
if (i == 0) {
List<NameValuePair> params = new ArrayList<NameValuePair>();
JSONObject json = jParser.makeHttpRequest(url_daftar_rs, "GET",
params);
Log.d("All Products: ", json.toString());
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
daftar_rs = json.getJSONArray(TAG_DAFTAR_RS);
for (int i = 0; i < daftar_rs.length(); i++) {
JSONObject c = daftar_rs.getJSONObject(i);
String id_rs = c.getString(TAG_ID_RS);
String nama_rs = c.getString(TAG_NAMA_RS);
String link_image_rs = c
.getString(TAG_LINK_IMAGE_RS);
String alamat_rs = c.getString(TAG_ALAMAT_RS);
String telepon_rs = c.getString(TAG_TELEPON_RS);
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_ID_RS, id_rs);
map.put(TAG_NAMA_RS, nama_rs);
map.put(TAG_LINK_IMAGE_RS, link_image_rs);
map.put(TAG_ALAMAT_RS, alamat_rs);
map.put(TAG_TELEPON_RS, telepon_rs);
DaftarRS.add(map);
}
} else {
}
} catch (JSONException e) {
e.printStackTrace();
}
}
else{ finish();
}
return null;
}
JSON PARSER:
public class JSONParser {
static InputStream is = null;
static JSONObject jObj = null;
static String json = "";
public JSONParser() {
}
// function get json from url
// by making HTTP POST or GET method
public JSONObject makeHttpRequest(String url, String method,
List<NameValuePair> params) {
// Making HTTP request
try {
// check for request method
if (method == "POST") {
// request method is POST
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} else if (method == "GET") {
// request method is GET
DefaultHttpClient httpClient = new DefaultHttpClient();
String paramString = URLEncodedUtils.format(params, "utf-8");
url += "?" + paramString;
HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
// try parse the string to a JSON object
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
// return JSON String
return jObj;
}
}
LISTADAPTER:
public class ListAdapter extends BaseAdapter {
private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater = null;
public ImageLoader imageLoader;
public ListAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
activity = a;
data = d;
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader = new ImageLoader(activity.getApplicationContext());
}
public int getCount() {
return data.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
if (convertView == null)
vi = inflater.inflate(R.layout.item_list_rs, null);
TextView id_rs = (TextView) vi.findViewById(R.id.id_rs);
TextView nama_rs = (TextView) vi.findViewById(R.id.nama_rs);
TextView link_image_rs = (TextView) vi.findViewById(R.id.link_image_rs);
TextView alamat_rs = (TextView) vi.findViewById(R.id.alamat_rs);
TextView telepon_rs = (TextView) vi.findViewById(R.id.telepon_rs);
ImageView thumb_image = (ImageView) vi.findViewById(R.id.image_rs);
HashMap<String, String> daftar_rs = new HashMap<String, String>();
daftar_rs = data.get(position);
id_rs.setText(daftar_rs.get(ListadoActivity.TAG_ID_RS));
nama_rs.setText(daftar_rs.get(ListadoActivity.TAG_NAMA_RS));
link_image_rs.setText(daftar_rs.get(ListadoActivity.TAG_LINK_IMAGE_RS));
alamat_rs.setText(daftar_rs.get(ListadoActivity.TAG_ALAMAT_RS));
telepon_rs.setText(daftar_rs.get(ListadoActivity.TAG_TELEPON_RS));
imageLoader.DisplayImage(daftar_rs.get(ListadoActivity.TAG_LINK_IMAGE_RS),
thumb_image);
return vi;
}
}
Why don't you add an EditText to the layout xml and pass the text as an argument after the List<NameValuePair> params = new ArrayList<NameValuePair>();
Something like:
params.add(new BasicNameValuePair(TAG_NAME, name));

Categories

Resources