我正在尝试获取列表中的以下视图
以下是我使用的代码
package 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是
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;
}
}
我无法得到这个观点。但没有错误即将来临。任何人都可以帮我解决这个问题吗?
Xml文件
<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>
自定义视图
<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>
答案 0 :(得分:3)
在getView()
方法的底部添加以下行,并检查您是否收到了您的观点。
return convertView;
将您的班级替换为现在正在使用的以下班级:
(注意:我已经删除了所有布局中的图像以使其运行,因为我没有任何你的图像)
1)ActivityJobByCategory.java
package com.example.c109.temp;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
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;
public class ActivityJobByCategory extends AppCompatActivity {
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);
android.support.v7.app.ActionBar bar = getSupportActionBar();
// 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.class, R.anim.close_next);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
finish();
//overridePendingTransition(R.anim.open_main, R.anim.close_next);
}
public class JobsAdapter extends BaseAdapter {
// View lookup cache
ArrayList<JobsByCategory> orders = new ArrayList<>();
Context mContext;
private class ViewHolder {
TextView job_name, job_location, date, packages, job_type;
}
/*@Override
public int getCount() {
return orders.size();
}*/
public JobsAdapter(Context context, ArrayList<JobsByCategory> orders) {
mContext = context;
this.orders = orders;
}
@Override
public int getCount() {
return orders.size();
}
@Override
public Object getItem(int position) {
return orders.get(position);
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Get the data item for this position
final JobsByCategory jobs = (JobsByCategory) 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(mContext);
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;
}
}
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 {
this.progressDialog.dismiss();
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);
}
// 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());
}
}
}
}
2)job_list.xml
<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: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:padding="7dp"
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"
/>
</LinearLayout>
<ListView
android:visibility="visible"
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:textSize="14sp"
android:layout_centerInParent="true"
android:visibility="gone"/>
3)menu_list_item.xml
<LinearLayout
android:layout_width="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
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:layout_alignParentLeft="true"
android:padding="10sp"
android:text="aaa"
android:textSize="14sp"
android:layout_alignParentStart="false"
android:layout_alignParentEnd="false"
android:layout_alignParentRight="false"/>
<TextView
android:id="@+id/dates"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
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: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>
答案 1 :(得分:1)
为什么getCount
被评论你的适配器如何知道项目的数量
你致电final JobsByCategory jobs = getItem(position)
;
但没有计数
答案 2 :(得分:1)
使用ArrayAdapter的视图很复杂,请尝试使用BaseAdapter。
1_将extends ArrayAdapter<JobsByCategory>
更改为extends BaseAdapter
2_更改您的代码,如下所示:
ArrayList<JobsByCategory> mOrderList;
Context mContext;
public JobsAdapter(Context context, ArrayList<JobsByCategory> orders) {
mContext = context;
mOrderList = orders;
}
@Override
public JobsByCategory getItem(int position) {
return mOrderList.get(position)
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public int getCount() {
return mOrderList.size();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
...
if (convertView == null) {
viewHolder = new ViewHolder();
LayoutInflater inflater = LayoutInflater.from(mContext);
...
}
3_你的xml有问题:
<ListView
android:visibility="gone"
将gone
更改为visible
或删除此行
并尝试再次测试它!