Я новичок в программировании для Android и пытаюсь реализовать listview
, который заполняется из базы данных. Я хочу иметь actionbar
с навигационным ящиком в своем приложении. Однако, поскольку mainactivity.java
расширяет listview
, невозможно расширить класс appcompatibility
.Панель действий, навигационный ящик со списком
Я пытаюсь найти решение в Интернете, но не могу найти что-либо конкретное. В любом случае мы можем это реализовать? Если есть какой-либо ресурс, пожалуйста, укажите это.
ниже код моего activity_main.xml
<LinearLayout 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"
tools:context=".MainActivity" >
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
У меня есть еще один файл макета app_custom_list.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/appIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="3dp"
android:layout_marginTop="3dp"/>
//android:src="@drawable/facebook" />
<TextView
android:id="@+id/titleTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/appIcon"
android:layout_toRightOf="@id/appIcon"
android:layout_marginLeft="3dp"
android:text="Application Title"
android:textSize="22dp"/>
<TextView
android:id="@+id/dlTxt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/titleTxt"
android:layout_marginLeft="10dp"
android:layout_marginRight="3dp"
android:text="description"
android:textSize="18dp"/>
</RelativeLayout>
Мой main_activity.java
файл ниже:
package com.example.gurje.beyondteaching1;
import java.util.List;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class MainActivity extends ListActivity implements FetchDataListener{
private ProgressDialog dialog;
private String[] mPlanetTitles;
private ListView mDrawerList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
}
private void initView() {
// show progress dialog
dialog = ProgressDialog.show(this, "", "Loading...");
String url = "http://192.168.0.29:8080/connect.php";
FetchDataTask task = new FetchDataTask(this);
task.execute(url);
}
@Override
public void onFetchComplete(List<Application> data) {
// dismiss the progress dialog
if(dialog != null) dialog.dismiss();
// create new adapter
ApplicationAdapter adapter = new ApplicationAdapter(this, data);
// set the adapter to list
setListAdapter(adapter);
}
@Override
public void onFetchFailure(String msg) {
// dismiss the progress dialog
if(dialog != null) dialog.dismiss();
// show failure message
Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
}
public void NavigationDrawer(){
}
}
Теперь я хочу, чтобы добавить actionbar
к нему, но, как я уже простирающийся listactivity
, я не могу продлить appcompat
, который необходим для реализации actionbar
Вы описали несколько различных вещей (NavigationDrawer, ActionBar, AppCompat, ListView) .. Его трудно увидеть, что вы rellay пытались до Теперь. Пожалуйста, предоставьте код, чтобы мы могли вам помочь. – Joehl
Один из вариантов заключается в том, чтобы mainactivity.java расширяет Activity, а затем устанавливает корневой режим макета как ListView. Сделав это, вы можете изменить панель действий. – programmer23
Привет, пожалуйста, помогите .. я полностью застрял здесь – sandhu