我想从一个活动转移到另一个活动(使用虚拟设备).当我点击按钮移动时,我的模拟器会显示一个对话框unfortunately SMS1 has stopped working(SMS1是我的应用程序名称).
任何人都可以帮我纠正我的代码吗?
MainActivity.java:
package com.example.sms1;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity implements OnClickListener
{
Button b1;
TextView tv1;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = (Button) findViewById(R.id.button1);
tv1 = (TextView) findViewById(R.id.textView1);
b1.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu); …Run Code Online (Sandbox Code Playgroud) 我使用以下代码使android设备成为ftp服务器(Android内部存储).我得到了例外os.android.NetworkOnMainThread.我试图将onStart代码放入,AsyncTask但应用程序永远不会执行并在启动时崩溃.关于Android上的ftp服务器的任何帮助都会很棒,因为我不知道如何让它工作.
这是MainActivity守则
package com.googlecode.simpleftp;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;
public class FTPServer extends Activity {
private static int COMMAND_PORT = 2121;
static final int DIALOG_ALERT_ID = 0;
private static ExecutorService executor = Executors.newCachedThreadPool();
/** Called when the activity is first created. */
@Override
public void …Run Code Online (Sandbox Code Playgroud) 我正试图测试AlertDialog一下ActivityInstrumentationTestCase2.
这是原始代码:
this.setmBtAppelerFixe(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder dialog = new AlertDialog.Builder(InterventionImmobiliereDetailsActivity.this);
dialog.setTitle("Appel");
dialog.setMessage("Appeler le contact ?");
dialog.setCancelable(true);
dialog.setNegativeButton("Non", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
dialog.setPositiveButton("Oui", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
InterventionImmobiliereDetailsActivity.this.lancerIntentAppel(mIntervention.getTelContact());
}
});
mAdAppelerFixe = dialog.create();
mAdAppelerFixe.show();
}
});
Run Code Online (Sandbox Code Playgroud)
现在我无法点击正面按钮.此代码似乎不起作用:
mActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
assertTrue(mLLAppelerFixe.performClick());
AlertDialog mDialog = mActivity.getAdAppelerFixe();
assertTrue(mDialog.isShowing());
Button okButton = …Run Code Online (Sandbox Code Playgroud) 我一直在使用WCF(.svc)服务一段时间,请求格式是,JSON并且响应格式XML在Android应用程序中正常工作.几天前,我为DigiCert SSL的WCF服务实现了一个证书(使用我的通配符功能).该服务可从浏览器访问,并且不会显示错误.下面是WebConfig
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="IntermediateWebService.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<customErrors mode="Off"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="IntermediateWebService.WebBehavior">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpsGetEnabled="true"/>
<!-- To …Run Code Online (Sandbox Code Playgroud) 我试图将线性布局内的视频视图拉伸到全屏,但它与设备屏幕不匹配。这是我的代码
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="720dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_gravity="fill_horizontal"
android:layout_marginTop="140dp" >
<VideoView
android:id="@+id/videoView1"
android:layout_width="fill_parent"
android:layout_height="720dp" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
左右各有 10 到 15 dp 的空间。此外,线性布局不会拉伸到全屏。我希望它以宽度填充屏幕。
我正在尝试将选择器应用到我的列表视图,它是一个自定义列表视图,我尝试了很多选项,但没有任何工作.任何帮助将不胜感激.我附上了我的代码.提前致谢
selector_listview.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="@drawable/faintblue" />
<item android:state_focused="true" android:drawable="@drawable/yellow" />
</selector>
Run Code Online (Sandbox Code Playgroud)
layout_listview.xml
<?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"
android:background="#ffffff" >
<ListView
android:id="@+id/lvChatList"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/rlHeader"
android:background="@drawable/selector_expandable_listview"
android:listSelector="@drawable/selector_expandable_listview" >
</ListView>
<TextView
android:id="@+id/tvNoChats"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="No Chats"
android:visibility="gone" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
黄色背景效果有效发生但蓝色效果没有发生,请提前帮助谢谢
我正在尝试填充列表视图,并尝试在我的主要选择我的列表视图:
lv = (ListView) findViewById(R.layout.activity_main.xml.id);
Run Code Online (Sandbox Code Playgroud)
我的XML文件夹结构是:
RES>布局> activity_main.xml中
我的main_activity.xml文件看起来像这样:
<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" >
</ListView>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我认为这是一个简单的错误,我没有完全理解xml id值如何在android中工作.
string[][] myArray = new[size][];
for(int i=0;i<2;i++){
myArray[i][0] = newValue.toString();
}
Run Code Online (Sandbox Code Playgroud)
在分配值时,我得到一个错误,我得到了Object Reference not set to instance of object异常.请帮忙