小编zya*_*mys的帖子

android asynctask向ui发送回调

我有以下asynctask类,它不在活动中.在我正在初始化asynctask的活动中,我希望asynctask将回调报告回我的活动.可能吗?或者asynctask是否必须与活动位于同一个类文件中?

protected void onProgressUpdate(Integer... values) 
{
    super.onProgressUpdate(values);
    caller.sometextfield.setText("bla");
}
Run Code Online (Sandbox Code Playgroud)

像这样的东西?

android android-asynctask

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

RuntimeException:您的内容必须具有一个ListView,其id属性为'android.R.id.list'

我得到一个运行时异常

java.lang.RuntimeException:您的内容必须具有一个ListView,其id属性为'android.R.id.list'

我不知道出了什么问题.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.newslist);
    mDbHelper.open();
    fillData();
}

private void fillData() {
    Bundle extras = getIntent().getExtras();
    long catID = extras.getLong("cat_id");
    Cursor c = mDbHelper.fetchNews(catID);
    startManagingCursor(c);

    String[] from = new String[] { DBHelper.KEY_TITLE };
    int[] to = new int[] { R.id.newslist_text };

    SimpleCursorAdapter notes = new SimpleCursorAdapter(this, R.layout.text_newslist, c, from, to);
    setListAdapter(notes);
}
Run Code Online (Sandbox Code Playgroud)

newslist.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content">
    <ListView 
         android:id="@+id/catnewslist"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content">
    </ListView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

text_newslist.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"> …
Run Code Online (Sandbox Code Playgroud)

android

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

在Eclipse调试时,Android应用程序仅与SIGABRT Signal 6崩溃

我有一个应用程序在没有连接调试器的设备上运行完美.但是,在Eclipse中调试时遇到问题:

当主线程暂停大约10秒或更长时间时(例如在遇到断点之后),主线程抛出一个SIGABRT,显然来自libc.

我能想到的唯一解释是主线程上的消息队列在未被轮询时,会溢出来自另一个线程的消息.但是,当主线程被挂起时,我没有看到堆增长.此外,虽然我的应用程序在所有服务,内容提供商,广播接收器,http和地图工作者线程等之间有大约20个线程,但我真的不能想到任何过多消息的来源.

所以我的问题是:我该如何解决这个问题?我可以使用哪些工具以及如何在调试器中暂停时查找导致我的应用程序崩溃的原因?

编辑1:

logcat中唯一的东西是:

02-05 22:23:54.861: I/dalvikvm(26795): threadid=3: reacting to signal 3
02-05 22:23:54.901: D/dalvikvm(26795): threadid=1: still suspended after undo (sc=1 dc=1)
02-05 22:23:54.901: I/dalvikvm(26795): Wrote stack traces to '/data/anr/traces.txt'
02-05 22:23:58.905: A/libc(26795): Fatal signal 6 (SIGABRT) at 0x000002f5 (code=0), thread 26795 (om.myapp)
Run Code Online (Sandbox Code Playgroud)

编辑2:

进一步的调查让我相信它是故意杀死我的进程,因为它错误地认为UI线程被挂起.问题不在我的应用程序中.所以现在我的问题是:如何在调试时阻止Android杀死我的进程?

eclipse android sigabrt

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

如何禁用列表视图中的项目?

我有一个列表视图,通过数据库中的记录填充.现在我必须让一些记录可见,但无法选择,我该如何实现呢?

这是我的代码

public class SomeClass extends ListActivity { 
    private static List<String> products; 
    private DataHelper dh; 
    public void onCreate(Bundle savedInstanceState) { 
        dh = new DataHelper(this); 
        products = dh.GetMyProducts();  /* Returns a List<String>*/ 
        super.onCreate(savedInstanceState); 
        setListAdapter(new ArrayAdapter<String>(this, R.layout.myproducts, products)); 
        ListView lv = getListView();
        lv.setTextFilterEnabled(true); 
        lv.setOnItemClickListener( new OnItemClickListener() { 
            @Override 
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { 
                // TODO Auto-generated method stub 
                Toast.makeText(getApplicationContext(), ((TextView) arg1).getText(), Toast.LENGTH_SHORT).show(); 
            } 
        }); 
    } 
}
Run Code Online (Sandbox Code Playgroud)

布局文件myproducts.xml如下:

<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:padding="10dp" 
    android:textSize="16sp"> …
Run Code Online (Sandbox Code Playgroud)

android listviewitem android-widget

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

添加Overlay到OSMDROID

这段时间我一直在苦苦挣扎.我想在我的地图上添加叠加层.我正在使用开源OSMdroid.但我得到的例子是从一个角落到另一个角落的直线红线.我的目标是在我的geoPoint设置中添加一些图标.

这是我的代码:

 package osmdemo.demo;

import java.util.List;

import microsoft.mappoint.TileSystem;

import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapController;
import org.osmdroid.views.MapView;
import org.osmdroid.views.MapView.Projection;
import org.osmdroid.views.overlay.Overlay;
import org.osmdroid.views.overlay.ScaleBarOverlay;
import org.osmdroid.views.util.constants.MapViewConstants;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.location.LocationManager;
import android.os.Bundle;

public class map extends Activity implements MapViewConstants
{

    /** Called when the activity is first created. */

    protected static final String PROVIDER_NAME = LocationManager.GPS_PROVIDER;
    MapController mapController;
    MapView mapView;
    ScaleBarOverlay mScaleBarOverlay;
    private MapOverlay mmapOverlay = null;
    private LocationManager mLocMgr; …
Run Code Online (Sandbox Code Playgroud)

android openstreetmap android-maps osmdroid

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

在Android中获取外部SDCard位置

我有一个预先存储在SD卡中的大量数据的应用程序.

我们支持所有平板电脑ICS以上.我无法找到在所有设备上正确访问SDCard位置的方法.

我查看了这里给出的各种解决方案,但它们似乎并不适用于所有情况.寻找通用的解决方案.

即使有人能告诉我SDCard的所有可能挂载点.

我只针对Android平板电脑,如果可以缩小解决方案的范围.

android

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

Android RatingBar(填补下一个明星)

我有以下RatingBar:

<RatingBar
                android:id="@+id/ratingBar"
                android:layout_width="wrap_content"
                android:layout_height="35dp"
                android:numStars="5"
                android:max="5"
                android:stepSize="1.0"
                android:layout_marginTop="12dp"/>
Run Code Online (Sandbox Code Playgroud)

当我按下星形的左侧部分时 - 它被选中,但当我按下右侧部分时 - 选择了以下星形.我需要点击的星星被选中,无论我点击哪一部分.请帮助我理解出了什么问题.

android ratingbar

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

共享元素两个片段之间的转换,保持第一个片段可见

我在两个片段之间的共享元素转换正常工作.但是,问题是我不想隐藏第一个片段 - 我希望它显示在新添加的第二个片段下面.如果我不在ft.hide( firstFragment )FragmentTransaction的共享元素中包含转换将不会运行.

如何进行共享元素转换以保持两个片段可见?

android android-fragments shared-element-transition fragment-transitions

7
推荐指数
0
解决办法
211
查看次数

Android同步适配器资源

有没有人知道任何涵盖同步适配器及其用法的书籍或在线资源(开发文档除外)?我自己努力寻找任何好的材料.

或者..有没有人知道任何用于进行远程同步服务的替代库?

谢谢

android synchronization client-server

6
推荐指数
1
解决办法
2350
查看次数