我目前正在研究android项目并使用片段和ListViews/ListFragments.我有上下文操作栏来处理标准活动,例如ListActivity.
现在我尝试做同样的事情,但在片段布局上.我有一个MainActivity,它扩展了Activity,它为包含2个片段,片段A和片段B的布局扩展了XML.
片段A扩展了ListFragment并包含一个ListView,它从SQLite数据库中的数据填充.当我有一个上下文操作栏上的标准ListActivity工作,我有一个扩展ListView.MultiChoiceModeListener但是这不适用于一个ListFragment类或标准的活动,这样我将如何去实现这个类.
我想要实现的基本功能是当有人长时间在FragmentA中的ListView中按下项目时,它会扩展ListFragment,操作栏会在上下文中更改,然后用户可以从ListView中选择多个项目.
感谢您的任何帮助,您可以提供.
我有一个带有a 的自定义适配器,ListFragment但getView()根本没有调用适配器.
这是适配器的样子 -
public class ModuleListItemAdapter extends BaseAdapter {
List<ModuleItem> list;
Context context;
Module mod;
public ModuleListItemAdapter() {
super();
// TODO Auto-generated constructor stub
}
public ModuleListItemAdapter(Context context, List<ModuleItem> list, Module mod) {
super();
this.list = list;
this.context = context;
this.mod = mod;
// TODO Auto-generated constructor stub
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout rl = (RelativeLayout) inflater.inflate(R.layout.moduleitem, null);
GenerateModuleItemView gmiv …Run Code Online (Sandbox Code Playgroud) 我有一个活动,使用加载程序回调从服务器加载数据列表.我必须将数据列出到扩展的片段中
SherlockListFragment
Run Code Online (Sandbox Code Playgroud)
我尝试使用提交片段
Fragment newFragment = CategoryFragment.newInstance(mStackLevel,categoryList);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.add(R.id.simple_fragment, newFragment).commit();
Run Code Online (Sandbox Code Playgroud)
在onLoadFinished中,它给出了一个IllegalStateException说
java.lang.IllegalStateException: Can not perform this action inside of onLoadFinished
Run Code Online (Sandbox Code Playgroud)
我在actionbar sherlock中引用了这个例子,但是这些例子在片段中有加载器而不是活动.
任何人都可以帮助我这个o我可以修复它而无需从片段调用加载器!
我需要使用一组线性布局构建布局.布局必须占据屏幕的定义百分比.我需要这样做才能在所有设备上看到类似的外观.
我在右上角的布局中有一个textview(绿色框).每当我在textview中添加一些数据时,它会扰乱整个布局,如下图所示.但是当我到达屏幕/布局的右端时,我需要自动包装数据.
请帮我解决这个问题.提前致谢


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
android:orientation="vertical"
android:weightSum="100">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="91"
android:weightSum="100">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="40"
android:weightSum="235">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:background="#ff0000"
android:layout_weight="100">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ffff00"
android:layout_weight="45">
<ViewFlipper
android:id="@+id/view_flipper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/tvItemName" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</ViewFlipper>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ffffff"
android:layout_weight="90">
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="60"
android:weightSum="100">
<LinearLayout
android:layout_width="match_parent" …Run Code Online (Sandbox Code Playgroud) 我创建了一个ListFragment使用以下自定义布局,它添加了TextView一个在列表为空时显示消息:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView android:id="@id/android:list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:drawSelectorOnTop="false"/>
<TextView android:id="@id/android:empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/vsl_empty"
android:gravity="center"
android:layout_gravity="center"
android:textColor="#8C8C8C" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
使用派生自的自定义适配器加载数据CursorAdapter.当数据库中有数据时,列表会非常简短地显示空列表消息,直到加载数据,此时列表将被填充.
如何阻止空列表消息短暂显示,因为列表尚未填充?
更新
我想强调的是,我使用的是ListFragment与包含布局ListView与特定的id android:list,并且TextView用特殊的ID android:empty,如解释在这里.
设置android:visibility="invisible"不会影响可见性.我怀疑这是因为它被设置为内部可见.
我试图使用片段在列表视图中显示元素.我创建了自定义视图,如下所示
list_row.xml的图形表示

list_row.xml
<?xml version="1.0" encoding="utf-8"?>
<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="wrap_content"
android:orientation="horizontal"
android:padding="5dip" >
<!-- ListRow Left sied Thumbnail image -->
<LinearLayout
android:id="@+id/thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dip"
android:padding="3dip" >
<ImageView
android:id="@+id/list_image"
android:layout_width="50dip"
android:layout_height="50dip"
android:contentDescription="@string/image_desc"/>
</LinearLayout>
<!-- Menu name -->
<TextView
android:id="@+id/menu_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/thumbnail"
android:layout_toRightOf="@+id/thumbnail"
android:text="@string/menu_name"
android:textColor="#040404"
android:textSize="15sp"
android:textStyle="bold"
android:typeface="sans" />
<!-- Description -->
<TextView
android:id="@+id/description"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/thumbnail"
android:layout_below="@id/menu_name"
android:layout_marginTop="1dip"
android:layout_toRightOf="@+id/thumbnail"
android:text="@string/description"
android:textColor="#343434"
android:textSize="10sp"
tools:ignore="SmallSp" />
<!-- Price -->
<TextView
android:id="@+id/price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@id/menu_name"
android:layout_marginRight="5dip"
android:gravity="right"
android:text="@string/price"
android:textColor="#10bcc9" …Run Code Online (Sandbox Code Playgroud) android android-custom-view android-listview android-listfragment
我有一个扩展的ListFragment,这个onViewCreated()
public void onViewCreated(View v,Bundle savedInstanceState) {
super.onViewCreated(v, savedInstanceState);
mListener.onFragmentAction(0x000A);
if (mAdapter != null) {
getListView().setAdapter(mAdapter);
}
}
Run Code Online (Sandbox Code Playgroud)
mListener.onFragmentAction调用main活动来附加一些侦听器并将适配器发送到片段的listView(logFrag是活动的引用MyListFragment)
public void populateLogFrag() {
//line 225 logFrag.getListView().setOnItemLongClickListener(myEventListener);
logFrag.getListView().setOnItemClickListener(myEventListener);
refreshLogAdapter(provideLogAdapter());
}
Run Code Online (Sandbox Code Playgroud)
应用程序加载正常,但在配置更改(设备旋转)后,我得到以下堆栈跟踪:
11-22 14:58:24.336: E/AndroidRuntime(22261): Caused by: java.lang.IllegalStateException: Content view not yet created
11-22 14:58:24.336: E/AndroidRuntime(22261): at android.support.v4.app.ListFragment.ensureList(ListFragment.java:328)
11-22 14:58:24.336: E/AndroidRuntime(22261): at android.support.v4.app.ListFragment.getListView(ListFragment.java:222)
11-22 14:58:24.336: E/AndroidRuntime(22261): at com.berrmal.timetracker.MainActivity.populateLogFrag(MainActivity.java:225)
11-22 14:58:24.336: E/AndroidRuntime(22261): at com.berrmal.timetracker.MainActivity.onFragmentAction(MainActivity.java:282)
11-22 14:58:24.336: E/AndroidRuntime(22261): at com.berrmal.timetracker.MyListFragment.onViewCreated(MyListFragment.java:23)
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚为什么还没有创建ListView,因为我在片段的onCreateView方法已经返回之后以及在onViewCreated()期间调用它.我发现了一个或两个相关标题的线程,但解决方案似乎并不适用于此.
我想实现类似于Google Play的列表布局,其中包含每个行的菜单.请帮我创建一个.

我是否需要创建弹出菜单,或者有任何可用的选项来实现此目的.
谢谢
android android-custom-view android-listview android-listfragment
我正在尝试创建一个ArrayAdapter用于我的自定义ListFragment.现在没有任何东西显示在ListFragment除了TextView说什么碎片号码之外.我在getView()我的适配器的方法中放了一个断点,它没有被调用.我搜索了不会被调用的原因,有些人似乎认为我的ListView被隐藏了,所以我尝试更改layout_height为wrap_content,但这不起作用.
此外,我一直在关注此开发人员页面中的代码:http://developer.android.com/reference/android/support/v4/app/FragmentPagerAdapter.html
ListFragment:
public class HomeFragment extends ListFragment implements FragmentTitle
{
private int mNum = 0;
private String mTitle = "Home";
private ListView mListView;
private MyArrayAdapter mAdapter;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
mNum = getArguments() != null ? getArguments().getInt("num") : 1;
InfoContainer temp = new InfoContainer("test1", "test2");
mAdapter = new MyArrayAdapter(getActivity(), android.R.id.list, temp);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, …Run Code Online (Sandbox Code Playgroud) android android-arrayadapter android-viewpager android-listfragment
我有一个ListFragment,我使用自定义适配器来填充listview.一切顺利,直到我改变方向和滚动.然后它看起来像这样:

我猜这与我对视图持有者摸索有关,但我现在无法访问代码.