Android 无法使用自定义ListView布局
我正在尝试创建一个自定义的Android 无法使用自定义ListView布局,android,android-fragments,android-listview,Android,Android Fragments,Android Listview,我正在尝试创建一个自定义的列表视图,但我甚至无法编译它,因为它很早就给了我这个错误: Error:(25, 63) error: cannot find symbol variable listing 其中“listing”是我的ListView布局的xml文件名 我做错了什么? 这是我的片段代码: import android.app.Fragment; import android.os.Bundle; import android.view.LayoutInflater; import
列表视图
,但我甚至无法编译它,因为它很早就给了我这个错误:
Error:(25, 63) error: cannot find symbol variable listing
其中“listing”是我的ListView
布局的xml文件名
我做错了什么?
这是我的片段代码:
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
public class ListingFragment extends Fragment {
private CustomcursorAdapter mCustomcursorAdapter;
private ListView mListView;
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_listing, container, false);
//CursorAdapter
mCustomcursorAdapter = new CustomcursorAdapter(view.getContext(), null, 0);
//ListView
mListView = (ListView) view.findViewById(R.id.listing);
mListView.setAdapter(mCustomcursorAdapter);
return view;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
}
片段列表
<?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">
</RelativeLayout>
主要活动
import android.app.Activity;
import android.app.FragmentManager;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager.findFragmentById(android.R.id.content) == null) {
Listing listing = new Listing();
fragmentManager.beginTransaction().add(android.R.id.content, listing).commit();
}
}
}
<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"
tools:context="${relativePackage}.${activityClass}">
<TextView
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
在fragment\u listing.xml中,您应该添加:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/listing"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="@android:color/transparent" >
</ListView>
</RelativeLayout>
发布你的片段清单。xml@Ultimo_m片段布局Posted应该显示什么?现在它可以很好地编译,但我正在显示我的活动\ U主布局!这将显示您的片段布局,是否要显示它?这将显示我的活动\u主布局!看,片段列表是您的片段xml,您的活动布局是什么?
<FrameLayout
android:id="@+id/fragmentContainer"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
FragmentTransaction transaction = getFragmentManager().beginTransaction();
Fragment fragment = new Listing();
transaction.replace(R.id.fragmentContainer,fragment);
ft.addToBackStack(null);
ft.commit();