我有以下asynctask类,它不在活动中.在我正在初始化asynctask的活动中,我希望asynctask将回调报告回我的活动.可能吗?或者asynctask是否必须与活动位于同一个类文件中?
protected void onProgressUpdate(Integer... values)
{
super.onProgressUpdate(values);
caller.sometextfield.setText("bla");
}
Run Code Online (Sandbox Code Playgroud)
像这样的东西?
我正在尝试根据其中一个字符串字段过滤数组.
nameLower和filterLower都有NSString值,但我一直得到:
__NSCFString containsString:]: unrecognized selector sent to instance 0x7f876b79e160
-(void) filterFriendsArray:(NSString*)filter {
[_filteredFriendsArray removeAllObjects];
for (FacebookUser* user in _friendsArray)
{
NSString* nameLower = [user.user.name lowercaseString];
NSString* filterLower = [filter lowercaseString];
if ([nameLower containsString:filterLower])
[_filteredFriendsArray addObject:user];
}
_displayedFriendsArray = _filteredFriendsArray;
}
Run Code Online (Sandbox Code Playgroud) 我正在制作一个<layer-list>可绘制的.
我有我的背景图像,我希望第二层更小,但似乎无论我在我android:layer_width和我内部写的是什么android:layer_height.
第二层大小仍然相同.
这是我的xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<item
android:drawable="@drawable/picuser"
android:layout_width="50dp"
android:layout_height="50dp" />
<item
android:drawable="@drawable/ic_launcher"
android:layout_width="10dp"
android:layout_height="10dp" />
</layer-list>
Run Code Online (Sandbox Code Playgroud) 我已经使用AsyncTasks我的应用程序,以便懒惰下载和更新UI.
现在我AsyncTasks只是简单地更新UI:
protected void onProgressUpdate(String... values) {
super.onProgressUpdate(values);
gender.setText(values[0]);
}
Run Code Online (Sandbox Code Playgroud)
我的问题是如何检查性别所TextView呈现的活动是否仍然可用?
如果没有,我将收到错误,我的应用程序将关闭.
这是我在PHP中的try/catch块:
try
{
$api = new api($_GET["id"]);
echo $api -> processRequest();
} catch (Exception $e) {
$error = array("error" => $e->getMessage());
echo json_encode($error);
}
Run Code Online (Sandbox Code Playgroud)
如果没有任何内容$_GET["id"],我仍然会收到通知错误.如何避免出现此错误?
我有一个显示UIImage的UIImageView.
UIImage可能会改变为不同大小的其他UIImage,内部UIImage的位置和大小会根据它而改变.
我的问题是我正在尝试添加一个将在UIImage末尾的视图(它一直在变化),我所能得到的只是UIImageView的框架(它一直保持全屏).
如何获得当前显示UIImage的"框架"?
我已经使用了所有可用的手册,最后我设法将v7支持添加到我的android版本2.3项目中.
我正在尝试添加ActionBarActivity,但无法找到它...虽然找到了ActionBar ...
这是我试图获得ActionBarActivity.

这是我的SDK Manager
如您所见,我可以导入v7路径,但没有ActionBarActivity
我在我的应用程序中运行了一个服务..
此服务有一个用于向服务器发送消息的对象以及一个获取该对象并使用它的函数.
该对象是从服务初始化的,但是当UI获取此对象并使用它时 - 看起来它在UI线程上使用它.
它是否正确 ?有没有办法让我的对象始终从服务线程运行?
public class ServerMessagesManager extends Service {
private ServerMessagesReceiver serverMessageReceiver;
@Override
public void onCreate() {
super.onCreate();
this.serverMessageReceiver = new ServerMessagesReceiver(app);
}
public ServerMessagesReceiver getServerMessagesReceiver()
{
return serverMessageReceiver;
}
}
Run Code Online (Sandbox Code Playgroud) 我见过这个帖子:如何实现一个关于实现监听器的监听器.
它实际上非常简单,但我不知道它是如何完成的以及如何在我自己的代码中实现.
我有这个静态变量变量:AppLoader.isInternetOn.我想构建一个监听器,它将监听这个变量并更新TextView.
我应该这样做吗?
构建一个接口:
public interface InternetStateListener {
public void onStateChange();
}
Run Code Online (Sandbox Code Playgroud)
在我的活动中运行它:
public class MyActivity extends Activity {
private InternetStateListener mListener;
setTheListener(this);
public void setTheListener(InternetStateListener listen) {
mListener = listen;
}
private void onStateChange() {
if (mListener != null) {
if (AppLoader.isInternetOn)
text.setText("on")
else
text.setText("off")
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个带有一些文本的聊天气泡.为此我创建了三个布局,在主线性布局内部我正在使用FramLayout,我正在设置一个9补丁背景到这个Framlayout.Inside的Framlayout我正在添加一个RelativeLayout我放置我的三个textViews和一个imageView.but键入长文本它走出FramLayout边界.我不知道我做错了什么或我缺少什么.当我使用小文本它仍然适合,但与大文本它甚至从FramLayout的背景边框出去.在附件我显示我的泡沫和雅虎IM泡沫.我正在尝试创建像雅虎但有一些不同的风格.请给我你的建议.我尝试了很多与不同方法,但没有获得成功.谢谢你提前..
在这里我放置我的布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/linearListLayout1">
<FrameLayout
android:id="@+id/frameLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bubbleblue" >
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minHeight="100dp">
<TextView
android:id="@+id/chattitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"/>
<TextView android:id="@+id/chatdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"/>
<TextView android:id="@+id/chatText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/chatstatus"
android:layout_below="@+id/chattitle"
android:layout_toLeftOf="@+id/chatstatus"
android:text="TextView" />
<ImageView
android:id="@+id/chatstatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/add_picture"
android:layout_alignParentRight="true"
android:layout_below="@+id/chatdate"
android:minHeight="2dip"
android:maxWidth="2sp"
android:maxHeight="2sp"
android:layout_marginRight="2dp"/>
</RelativeLayout>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)