Android 如何为Parse.com创建自定义ListView
我有一个列表视图,它根据我的查询在我的列表视图中显示餐厅的名称。不过,我希望能够展示的不仅仅是每家餐厅的名称。我希望能够在列表视图中显示每个项目的位置和等级。这是到目前为止我的代码Android 如何为Parse.com创建自定义ListView,android,listview,parse-platform,Android,Listview,Parse Platform,我有一个列表视图,它根据我的查询在我的列表视图中显示餐厅的名称。不过,我希望能够展示的不仅仅是每家餐厅的名称。我希望能够在列表视图中显示每个项目的位置和等级。这是到目前为止我的代码 public class ResterauntList extends Activity { String cValue = null; String lValue = null; String rValue = null; ProgressDialog mProgressDialog
public class ResterauntList extends Activity {
String cValue = null;
String lValue = null;
String rValue = null;
ProgressDialog mProgressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_resteraunt_list);
Bundle bdl = getIntent().getExtras();
cValue = bdl.getString("cValue");
lValue = bdl.getString("lValue");
rValue = getIntent().getStringExtra("restrauntName");
pickMethod();
}
@SuppressLint("DefaultLocale")
public void pickMethod() {
if (cValue == null) {
if (lValue == null) {
populateList(rValue, "name");
} else {
populateList(lValue.toLowerCase(), "area");
}
} else {
populateList(cValue, "cuisine");
}
}
private void populateList(final String Value, final String Key) {
ParseQueryAdapter.QueryFactory<ParseObject> factory = new ParseQueryAdapter.QueryFactory<ParseObject>() {
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public ParseQuery create() {
ParseQuery query = new ParseQuery("resdb");
query.whereEqualTo(Key, Value).addAscendingOrder("name");
return query;
}
};
ParseQueryAdapter<ParseObject> adapter = new ParseQueryAdapter<ParseObject>(
this, factory);
adapter.setTextKey("name");
adapter.setTextKey("area");
adapter.addOnQueryLoadListener(new OnQueryLoadListener<ParseObject>() {
@Override
public void onLoading() {
mProgressDialog = new ProgressDialog(ResterauntList.this);
mProgressDialog.setTitle(Value + " Restaurants Search");
mProgressDialog.setMessage("Loading...");
mProgressDialog.setIndeterminate(false);
mProgressDialog.show();
}
@Override
public void onLoaded(List<ParseObject> objects, Exception e) {
mProgressDialog.dismiss();
}
});
final ListView listView = (ListView) findViewById(R.id.restListView);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
ParseObject object = (ParseObject) listView
.getItemAtPosition(position);
String Id = object.getObjectId();
Intent i = new Intent(getApplicationContext(),
SingleRestraunt.class);
i.putExtra("restId", Id);
startActivity(i);
}
});
}
public类resteraintlist扩展活动{
字符串cValue=null;
字符串左值=null;
字符串rValue=null;
进程对话框;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u resteraint\u列表);
Bundle bdl=getIntent().getExtras();
cValue=bdl.getString(“cValue”);
左值=bdl.getString(“左值”);
rValue=getIntent().getStringExtra(“restrauntName”);
pickMethod();
}
@SuppressLint(“DefaultLocale”)
公共方法(){
如果(cValue==null){
if(左值==null){
大众列表(右值,“名称”);
}否则{
populateList(左值.toLowerCase(),“area”);
}
}否则{
大众主义者(cValue,“烹饪”);
}
}
私有void populateList(最终字符串值、最终字符串键){
ParseQueryAdapter.QueryFactory=新建ParseQueryAdapter.QueryFactory(){
@凌驾
@SuppressWarnings({“unchecked”,“rawtypes”})
公共ParseQuery创建(){
ParseQuery查询=新的ParseQuery(“resdb”);
查询.whereEqualTo(键,值).addAscendingOrder(“名称”);
返回查询;
}
};
ParseQueryAdapter=新的ParseQueryAdapter(
这家工厂);
adapter.setTextKey(“名称”);
适配器。setTextKey(“区域”);
addOnQueryLoadListener(新的OnQueryLoadListener(){
@凌驾
公共无效加载(){
mProgressDialog=新建进度对话框(resteraintlist.this);
mProgressDialog.setTitle(值+“餐厅搜索”);
设置消息(“加载…”);
mProgressDialog.setUndeterminate(false);
mProgressDialog.show();
}
@凌驾
已加载公共void(列出对象,异常e){
mProgressDialog.disclose();
}
});
最终ListView ListView=(ListView)findViewById(R.id.restListView);
setAdapter(适配器);
setOnItemClickListener(新的OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父级、视图、,
内部位置,长id){
ParseObject对象=(ParseObject)列表视图
.getItemAtPosition(位置);
String Id=object.getObjectId();
意图i=新意图(getApplicationContext(),
单身人士(姑妈、班级);
i、 putExtra(“restId”,Id);
星触觉(i);
}
});
}
这是xml文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.gastronomaapp.ResterauntList" >
<ListView
android:id="@+id/restListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:textSize="40sp" >
</ListView>
</RelativeLayout>
我已经阅读了许多关于自定义列表视图的教程,并大致了解了如何进行自定义,但我似乎不知道应该在代码中进行哪些更改。有人能告诉我如何专门针对我的上述代码进行此操作吗?这是一个很好的乞丐辅导:
只需复制粘贴行布局,看看getView方法是如何运行的…当我试图找出对当前代码所做的更改时,我发现有点困惑。例如,他们都将适配器定义为ArrayAdapter,而我的适配器用于解析。你能说得具体一点吗?一旦解析了内容,你就构建了一个ArrayList.S“解析内容时”的名称构建一个ArrayList。您只需创建一个列表并创建适配器。问题是parse.com库。