Ich versuche, die unten Ansicht zu erhalten, die in einer Liste istNicht in der Lage bekommen Blick in Listenansicht aufblasen mit benutzerdefinierten Adapter
Es folgt der Code, den ich
verwendetpackage com.solodroid.ecommerce;
import android.app.ActionBar;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.ColorDrawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Html;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.rakyow.srptjobportal.R;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
/**
* Created by user on 3/29/2016.
*/
public class ActivityJobByCategory extends Activity {
ArrayList<JobsByCategory> listOfJobs = new ArrayList<JobsByCategory>();
ListView listView;
Long categoryId;
ProgressBar prgLoading;
TextView txtAlert;
String jobName, jobLocation, fromDate, toDate, fromPackage, toPackage, jobType, jobguid;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.job_list);
ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.header)));
bar.setTitle("Jobs Found");
bar.setDisplayHomeAsUpEnabled(true);
bar.setHomeButtonEnabled(true);
// prgLoading = (ProgressBar) findViewById(R.id.prgLoading);
// txtAlert = (TextView) findViewById(R.id.txtAlert);
listView = (ListView) findViewById(R.id.listMenu);
Bundle extras = getIntent().getExtras();
if (extras != null) {
categoryId = extras.getLong("category_id");
}
new task().execute();
@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.
switch (item.getItemId()) {
case android.R.id.home:
// app icon in action bar clicked; go home
this.finish();
overridePendingTransition(R.anim.open_main, R.anim.close_next);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
class task extends AsyncTask<String, String, Void> {
private ProgressDialog progressDialog = new ProgressDialog(ActivityJobByCategory.this);
InputStream is = null;
String result = "";
protected void onPreExecute() {
progressDialog.setMessage("Loading...");
progressDialog.setIndeterminate(false);
progressDialog.setCancelable(false);
progressDialog.show();
progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
public void onCancel(DialogInterface arg0) {
task.this.cancel(true);
}
});
}
@Override
protected Void doInBackground(String... params) {
String url_select = "http://jobportal.rakyow.com/website/joblist/lists?catid=" + categoryId;
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url_select);
ArrayList<NameValuePair> param = new ArrayList<NameValuePair>();
try {
httpPost.setEntity(new UrlEncodedFormEntity(param));
HttpResponse httpResponse = httpClient.execute(httpPost);
Log.d("Amit", "executed httppost");
HttpEntity httpEntity = httpResponse.getEntity();
Log.d("Amit", "Got response");
// read content
is = httpEntity.getContent();
Log.d("Amit", "Got content");
} catch (Exception e) {
Log.e("log_tag", "Error in http connection " + e.toString());
}
try {
BufferedReader br = new BufferedReader(
new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = "";
while ((line = br.readLine()) != null) {
Log.d("Amit", "line = " + line);
sb.append(line + "\n");
}
is.close();
result = sb.toString();
Log.d("Amit", "Result = " + result);
} catch (Exception e) {
// TODO: handle exception
Log.e("log_tag", "Error converting result " + e.toString());
}
return null;
}
protected void onPostExecute(Void v) {
try {
JSONObject object = new JSONObject(result);
Log.d("Amit", "created jsonobject");
JSONArray userDetailsArray = object.getJSONArray("data");
Log.d("Amit", "Got userDetails");
ArrayList<String> items = new ArrayList<String>();
try {
for (int i = 0; i < userDetailsArray.length(); i++) {
JSONObject obj = userDetailsArray.getJSONObject(i);
Log.d("Amit", "inside " + i);
jobName = obj.getString("job_title");
jobLocation = obj.getString("location");
fromDate = obj.getString("from_date");
toDate = obj.getString("to_date");
fromPackage = obj.getString("from_package");
toPackage = obj.getString("package");
jobType = obj.getString("job_type");
jobguid = obj.getString("guid");
JobsByCategory job = new JobsByCategory(jobName, jobLocation, fromDate, toDate, fromPackage, toPackage, jobType, jobguid);
listOfJobs.add(job);
}
this.progressDialog.dismiss();
// get an output on the screen
//set adapter for listview
JobsAdapter adapter = new JobsAdapter(ActivityJobByCategory.this, listOfJobs);
listView.setAdapter(adapter);
Log.d("Amit", "adapter set");
} catch (JSONException e) {
e.printStackTrace();
}
} catch (Exception e) {
// TODO: handle exception
Log.e("log_tag", "Error parsing data " + e.toString());
}
}
}
public class JobsAdapter extends ArrayAdapter<JobsByCategory> {
// View lookup cache
private class ViewHolder {
TextView job_name, job_location, date, packages, job_type;
}/*@Override
public int getCount() {
return listOfOrders.size();
}*/
public JobsAdapter(Context context, ArrayList<JobsByCategory> orders) {
super(context, R.layout.menu_list_item, orders);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Get the data item for this position
final JobsByCategory jobs = getItem(position);
Log.d("Amit2", "reached adapter getView");
// Log.d("Akhilesh", loads.loadType);
// Check if an existing view is being reused, otherwise inflate the view
ViewHolder viewHolder; // view lookup cache stored in tag
if (convertView == null) {
viewHolder = new ViewHolder();
LayoutInflater inflater = LayoutInflater.from(getContext());
convertView = inflater.inflate(R.layout.menu_list_item, parent, false);
viewHolder.job_name = (TextView) convertView.findViewById(R.id.jobName);
viewHolder.job_location = (TextView) convertView.findViewById(R.id.jobLocation);
viewHolder.date = (TextView) convertView.findViewById(R.id.dates);
viewHolder.packages = (TextView) convertView.findViewById(R.id.salary);
viewHolder.job_type = (TextView) convertView.findViewById(R.id.jobType);
convertView.setTag(viewHolder);
Log.d("Amit", "set adapter view");
} else {
viewHolder = (ViewHolder) convertView.getTag();
Log.d("Amit", " not set adapter view");
}
// Populate the data into the template view using the data object
viewHolder.job_name.setText(jobs.jobName);
viewHolder.job_location.setText(jobs.location);
viewHolder.date.setText(jobs.fromDate + "-" + jobs.toDate);
viewHolder.packages.setText(jobs.fromPackage + "-" + jobs.toPackage);
viewHolder.job_type.setText(jobs.jobType);
Log.d("Amit", "set all values");
return convertView;
}
}
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
finish();
overridePendingTransition(R.anim.open_main, R.anim.close_next);
}
}
JobsByCategory .class- ist
package com.solodroid.ecommerce;
public class JobsByCategory {
String jobName;
String location;
String fromDate;
String toDate;
String fromPackage;
String toPackage;
String jobType;
String jobGuid;
// Constructor to convert JSON object into a Java class instance
public JobsByCategory(String jN, String lO, String fD, String tD, String fP , String tP , String jT , String gD) {
this.jobName = jN;
this.location =lO;
this.fromDate = fD;
this.toDate = tD;
this.fromPackage =fP;
this.toPackage =tP;
this.jobType =jT;
this.jobGuid =gD;
}
public String getJobName() {
return jobName;
}
public String getLocation() {
return location;
}
public String getFromDate() {
return fromDate;
}
public String getToDate(){
return toDate;
}
public String getFromPackage() {
return fromPackage;
}
public String getToPackage() {
return toPackage;
}
public String getJobType() {
return jobType;
} public String getJobGuid() {
return jobGuid;
}
}
Ich bin nicht in der Lage, die Aussicht zu bekommen. Aber keine Fehler kommen. Kann mir jemand helfen, dieses Problem zu lösen?
XML-Dateien
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#e7e7e7" >
<LinearLayout
android:id="@+id/lytSearch"
android:layout_width="fill_parent"
android:layout_height="45dp"
android:background="@color/header"
android:gravity="center_vertical"
android:visibility="visible" >
<EditText
android:id="@+id/edtKeyword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:background="@drawable/search_form"
android:hint="@string/search"
android:padding="7dp"
android:textColor="@color/hint"
android:textSize="14sp"
android:inputType="text"
android:singleLine="true" />
<ImageButton
android:id="@+id/btnSearch"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:background="@color/header"
android:src="@drawable/ic_search" />
</LinearLayout>
<ListView
android:visibility="gone"
android:id="@+id/listMenu"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/lytSearch"
android:divider="@null"
android:padding="5dp" />
<ProgressBar
android:id="@+id/prgLoading"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerInParent="true" />
<TextView
android:id="@+id/txtAlert"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/not_found"
android:textSize="14sp"
android:layout_centerInParent="true"
android:visibility="gone"/>
</RelativeLayout>
Benutzerdefinierte Ansicht
<LinearLayout
android:layout_width="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:background="@drawable/button_top_style_1"
android:orientation="vertical"
android:padding="5dp" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Accountant"
android:padding="10dp"
android:id="@+id/jobName"
android:textSize="18sp"
android:textStyle="bold|italic"
android:background="#7153ff"
android:clickable="true"
android:textColor="#ffffff" />
<RelativeLayout
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:background="#69c9ff">
<TextView
android:id="@+id/jobLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/dates"
android:drawableLeft="@drawable/placeholder"
android:layout_alignParentLeft="true"
android:padding="10sp"
android:text="aaa"
android:textSize="14sp"
android:layout_alignParentStart="false"
android:layout_alignParentEnd="false" />
<TextView
android:id="@+id/dates"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:drawableLeft="@drawable/calendar"
android:layout_centerVertical="true"
android:text="bbb" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:background="#69c9ff">
<TextView
android:id="@+id/salary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/jobType"
android:drawableLeft="@drawable/rupee"
android:layout_alignParentLeft="true"
android:layout_marginLeft="5dp"
android:padding="10sp"
android:text="4 lakhs"
android:textSize="14sp" />
<TextView
android:id="@+id/jobType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="Full Time"
android:autoText="true"
android:background="#ff8058"
android:padding="10dp"
android:textStyle="bold"
android:textColor="#ffffff" />
</RelativeLayout>
</LinearLayout>
In JobsAdapter unter dem getView müssen Sie Ansicht zurückgeben. – Sach
habe ich hinzugefügt..aber immer noch kein glück –
bitte post fehler was du hast ?? – Sach