小编Bar*_*rak的帖子

在方向更改中保留列表片段中的列表

我有一个使用片段的应用程序,所有这些片段都包含在一个活动中.活动以包含按钮菜单的片段开始,所有这些按钮都会导致各种listfragments替换原始按钮/菜单片段.

我的问题是,在方向更改时,如果活动正在显示其中一个列表视图,它将消失并返回按钮菜单.我理解为什么会发生这种情况......活动被破坏并重新创建,但不是如何解决它并通过方向更改维护列表视图/当前片段.

我已经找到setRetainInstance这里使用的例子,但我无法弄清楚如何将它应用于我的情况下使用按钮菜单或者我想要保留的片段可能是几个不同的片段之一.

下面是简化的代码,用于显示主要活动和其中一个listfragments.

任何指向添加内容的指针都将非常感激,以便保留列表片段.

活动

public class Main extends FragmentActivity {
    private MainMenuFragment menu;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        menu = new MainMenuFragment();
        getSupportFragmentManager().beginTransaction().replace(R.id.pane, menu).commit();    
    }
}
Run Code Online (Sandbox Code Playgroud)

ListFragment

public class ItemListFragment extends ListFragment {

    private TextView header;
    private TextView empty;
    private Button add;
    public static Cursor itemCursor;
    private GroceryDB mDbHelper;
    public static long mRowId;
    public static CheckCursorAdapter lists;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.common_list, …
Run Code Online (Sandbox Code Playgroud)

android android-listview android-fragments android-orientation

18
推荐指数
1
解决办法
1万
查看次数

突出显示可展开列表中的选定项目

我有一个布局,我在左边的片段中有一个可扩展列表,右边有一个细节片段.一切正常.

现在我想说明左边的哪个项目正在显示右边的详细信息,这里我遇到了问题.

在普通列表视图中,我通过将列表视图的选择模式设置为单个,然后使用基于"激活"状态的可绘制状态来实现此目的.当我单击该项目时,背景将设置为我选择的颜色并保持这种状态,直到我在列表中选择另一个项目.

我试着将它应用到我的可扩展列表视图中,这是一个令人沮丧的失败.没有错误,但所选项目没有保持其颜色状态.我不确定我是不是正确设置了它的选择模式(我已经在布局文件中尝试了它以及编程方式,它似乎没有什么区别),或者指向错误的东西(不知道那是怎么回事,但......)

任何帮助/指示赞赏(即使它是在一个完全不同的方向).

目前大多数失败:

可扩展的列表视图代码

private void fillData(String group, String child) {
    ExpandableListView lv;
    mGroupsCursor = mDbHelper.fetchGroup(group);
    getActivity().startManagingCursor(mGroupsCursor);
    mGroupsCursor.moveToFirst();
    lv = (ExpandableListView) getActivity().findViewById(R.id.explist);
    lv.setChoiceMode(ExpandableListView.CHOICE_MODE_SINGLE);        

    mAdapter = new MyExpandableListAdapter(mGroupsCursor, getActivity(),
            R.layout.explistlayout,
            R.layout.explistlayout,
            new String[] { "_id" },
            new int[] { android.R.id.text1 },
            new String[] { child },
            new int[] { android.R.id.text1 });
    lv.setAdapter(mAdapter);
    registerForContextMenu(lv);

    lv.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { 
        @Override 
        public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id)  
        { 
            mRowId  = id;
            EventDisplayFragment eventdisplay = new EventDisplayFragment(); …
Run Code Online (Sandbox Code Playgroud)

android android-widget android-layout

14
推荐指数
3
解决办法
3万
查看次数

ListFragment中的上下文菜单

我正在尝试为平板电脑创建一个应用程序,其主屏幕包含三个片段,每个片段包含一个列表.我想为每个列表启用上下文菜单,但每当我尝试我得到一个意外的程序停止和强制关闭.

以下是相关代码和xml的工作原理,并在我尝试添加上下文菜单之前,给出了我想要的三个片段,每个片段都有listview:

main.xml中

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="3dp">

<fragment class="cdc.ListFragment.Fragment1"
    android:id="@+id/fragment1"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1" />

<fragment class="cdc.ListFragment.Fragment2"
    android:id="@+id/fragment2"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1" />

<fragment class="cdc.ListFragment.Fragment3" 
    android:id="@+id/fragment3"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

fragment1.xml(另外两个相似)

    <TextView
        android:id="@+id/txtHeader1"
        android:layout_width="fill_parent"
        android:layout_height="30dp"
        android:layout_gravity="center"
        android:gravity="center"
        android:text="@string/machines_header"
        android:textColor="#00ccff"
        android:background="#ff23cf"
        android:textSize="25dp" />

    <ListView
        android:id="@id/android:list"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:drawSelectorOnTop="false"
        android:textSize="12dp" />

    <Button
        android:id="@+id/Button01"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:minHeight="25dp"
        android:text="@string/menu_add_machine"
        android:textSize="15dp" >
    </Button>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

ListFragment.java

import android.app.Activity;
import android.os.Bundle;

public class ListFragmentExampleActivity extends Activity {
    /** Called when the activity …
Run Code Online (Sandbox Code Playgroud)

android android-widget android-layout android-listview android-fragments

9
推荐指数
1
解决办法
1万
查看次数

维护片段中所选项目的突出显示?

我有两个片段的布局.左手片段是使用SimpleCursorAdaptor的ListFragment,右手一个片段填充有关从左片段中的列表中选择的项目的详细信息.我正在试图弄清楚如何确保ListFragment中的选定项目保持突出显示,直到选中列表中的另一个项目.

经过一些研究,我尝试使用android:background="@drawable/item_selector"我可以改变不同状态的颜色,但似乎没有一个持续存在.我认为所选择的......在你选择不同的项目之前,所选项目仍然是所选项目似乎是合乎逻辑的.

我甚至尝试v.setSelected(true);在我的clickhandler中使用希望它可以保持状态,但这也不起作用.

有一个我失踪的州吗?我浏览了开发文档,似乎没有其他任何东西......

item_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item 
        android:state_pressed="true" 
        android:drawable="@color/green" />
    <item 
        android:state_selected="true" 
        android:drawable="@color/blue" />
</selector>
Run Code Online (Sandbox Code Playgroud)

我不确定其他代码可能会有什么帮助,所以请随意询问您认为必要的其他内容.

android android-widget android-layout

9
推荐指数
1
解决办法
7349
查看次数

在OSMDroid中下载特定的maptile到缓存

我目前正在研究一个学校项目,我正在尝试学习将OSM地图图块下载到手机的本地内存/缓存中的技术,以便用户能够在离线时查看地图.

这是通过给出特定位置来完成的,并且在距离该位置的特定半径/距离内的地图图块将被下载到手机存储器中(当存在在线连接时)以用于离线显示.

但是,我在理解OSMDroid的API方面遇到了一些麻烦.根据我的理解,所涉及的课程似乎是:

如果我弄错了,请纠正我.

另外,在MapTileBase(我认为是提供者)中,getMapTile返回android.graphics.drawable.Drawable.

这个Drawable类甚至与离线地图显示的概念有关吗?

希望有人可以告诉我在哪里准确地将地图下载到手机的内存中,以及我们如何编辑地图以显示路线,引脚等界面项目.

maps android offline-caching osmdroid

9
推荐指数
1
解决办法
2490
查看次数

Google Calendar以2种方式与php同步

我正在创建一个使用Google Calendar API的php网站.它在创建,更新和删除方面运行良好:登录后,PHP网站上的任何事件都会进入我的Google日历活动.

我网站上创建的活动是在Google日历中创建的.

我现在想要的是:当我从测试页面创建一个事件后,它会在登录后进入Google日历,然后如果我从Google日历更新或删除该事件,那么它应该自动更新或删除php网站事件.

基本上:单向同步工作正常,但现在我想要双向同步.

如果有人有任何想法,请与我分享,我将不胜感激.

php google-calendar-api

8
推荐指数
1
解决办法
1万
查看次数

如何在android中以编程方式控制横向和纵向?

我使用android sdk 4.0在应用程序上开发,然后在我的三星选项卡中安装.apk文件.当我运行该应用程序时,它正常工作.如果我将标签纵向更改为横向或反向,则屏幕也会更改.

但我的要求是无论是纵向还是横向更改模式到横向到纵向,我的应用程序应该只在纵向模式下运行.

android

8
推荐指数
3
解决办法
2万
查看次数

如何强制重绘listview?

这个问题与其他类似标题略有不同.我不是要更新列表中的数据,我正在尝试更新列表的外观.

我的应用程序基于片段使用支持库.我有一个PreferenceActivity,我允许用户为列表中的文本设置他们想要的颜色(适配器读取首选项并设置颜色).这在大多数情况下都按预期工作.

我遇到的问题如下.当我在屏幕上显示列表(它是一个ListFragment)并拉出菜单时,选择"首选项"并更改颜色首选项.从PreferenceActivity返回列表后,我似乎无法使用指定的新颜色重新绘制列表.

如果我离开列表并返回它,它将使用新颜色重新生成.

我试图用来onResume做出改变.我目前拥有的代码(似乎没有对列表执行任何操作,但会更改标题颜色):

@Override
public void onResume() {
    super.onResume();
    header.setTextColor(MyApplication.header);
    line.setBackgroundColor(MyApplication.header_line);
    subheader.setTextColor(MyApplication.header);
    getListView().invalidateViews();
}
Run Code Online (Sandbox Code Playgroud)

我曾尝试invalidateViewsinvalidate.无奈之下,我试着调用notifyDataSetChanged适配器,即使数据本身没有变化.似乎没什么用.

我错过了一些明显的东西,还是没有办法做到这一点?

编辑

我的适配器的'getView`方法:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null)
        convertView = View.inflate(context, layout, null);
    View row = convertView;
    c.moveToPosition(position);
    TextView first = (TextView) convertView.findViewById(R.id.ListItem1);
    TextView second = (TextView) convertView.findViewById(R.id.ListItem2);
    TextView third = (TextView) convertView.findViewById(R.id.ListItem3);
    TextView fourth = (TextView) convertView.findViewById(R.id.ListItem4);

    DecimalFormat df = new DecimalFormat("0.00");
    Double …
Run Code Online (Sandbox Code Playgroud)

android android-widget android-listview android-adapter

7
推荐指数
1
解决办法
2万
查看次数

添加内部超链接到 pdf

我有一个 PDF 文档,我想向其中添加内部超链接。具体来说,第 1 页包含一个我想要使其可点击的目录。我的想法是在第 1 页的预定位置创建矩形框,该矩形框应链接到第 2、3、...

我发现这篇文章讨论了使用上面描述的方法添加内部超链接。 http://bugs.ghostscript.com/show_bug.cgi?id=691531

但是,当我尝试在文件中使用此技术时,脚本仅添加带有矩形和超链接的页面。我需要它将超链接覆盖在我的第一页的现有内容上。

pdf hyperlink ghostscript

5
推荐指数
1
解决办法
5455
查看次数

相对布局视图重叠

所需的布局是一个标题,下面有两个框架(稍后包含片段)和固定在屏幕底部的按钮:

     Header Text     
----------------------
frame 1   |  frame 2
----------------------
btn 1   btn 2   btn 3
Run Code Online (Sandbox Code Playgroud)

我几乎已经排序(最后是xml),有一个问题......两个框架重叠按钮。

我已经对该问题进行了一些搜索并发现了这一点,但所做的只是将我的问题从溢出按钮的框架更改为溢出标题的框架。

我还尝试将按钮设置为显示在框架下方而不是与父项的底部对齐,但这只是将它们推离了屏幕。

当前布局xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <TextView
            android:id="@+id/fdname"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:clickable="true"
            android:gravity="center"
            android:text="No department info has been entered yet"
            android:textSize="25dp" />
    <TextView
            android:id="@+id/fdaddress"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/fdname"
            android:gravity="center"
            android:text="address"
            android:textSize="15dp" />
    <TextView
            android:id="@+id/horizontalline"
            android:layout_width="match_parent"
            android:layout_height="2dip"
            android:layout_below="@id/fdaddress"
            android:background="#ff23cf"
            android:gravity="center_vertical"
            android:paddingBottom="2dip"
            android:paddingTop="2dip" />
    <LinearLayout
            android:id="@+id/frames"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/horizontalline"
            android:orientation="horizontal" >
            <FrameLayout
                    android:id="@+id/leftpane"
                    android:layout_width="0px"
                    android:layout_height="match_parent"
                    android:layout_weight="1" />
            <TextView …
Run Code Online (Sandbox Code Playgroud)

android android-layout

4
推荐指数
1
解决办法
1万
查看次数