我打算用layout_weight = 1创建3个按钮,对自定义对话框不感兴趣.所以我写了下面的代码.它不工作.总是是按钮给我null.这段代码怎么了?
AlertDialog dialog= new AlertDialog.Builder(this).create();
dialog.setIcon(R.drawable.alert_icon);
dialog.setTitle("title");
dialog.setMessage("Message");
dialog.setButton(AlertDialog.BUTTON_POSITIVE,"Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
}
});
Button yesButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
Log.w("Button",""+yesButton);//here getting null
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1f);
yesButton.setLayoutParams(layoutParams);
dialog.show();
Run Code Online (Sandbox Code Playgroud)
此致,Android开发人员.
我已经在实施项目工作正常后使用第三方库(zxing)实现了项目,然后我编写了一个测试项目来对我的项目进行单元测试.运行测试项目后,主项目,类和它的方法都没有给出任何项目.错误,但如果在主项目的方法中使用了任何zxing框架类,那么在运行时尚未编译时会出现上述错误.请告诉我如何解决此问题?
在Android中我是否有任何与IPhone Aspect Fill相关的概念.我想在imageview上的android图像中包含这个相同的概念.请给我这个概念的代码片段?
我有这个HTML输入:
<font size="5"><p>some text</p>
<p> another text</p></font>
Run Code Online (Sandbox Code Playgroud)
我想使用正则表达式删除HTML标记,以便输出为:
some text
another text
Run Code Online (Sandbox Code Playgroud)
任何人都可以建议如何用正则表达式做到这一点?
我已经使用requestFocus()编写了setFocus到ALert Dialog负按钮的代码.但按钮颜色不会改变.我可以手动将背景图像设置为该按钮.但是我需要直接来自native.How如何将焦点放在ALlert Dialog中的第二个按钮?
我发送代码片段以便理解
alertbox.show();
alertbox.getButton(AlertDialog.BUTTON_NEGATIVE).requestFocus();
Run Code Online (Sandbox Code Playgroud)
即使我尝试过
alertbox.show();
alertbox.getButton(AlertDialog.BUTTON_NEGATIVE).requestFocus(View.FOCUS_FORWARD)
Run Code Online (Sandbox Code Playgroud)
请问任何人都可以回复此查询吗?
此致,Android Developer
我正在使用下面的代码来遍历我的列表,如果List Items可见,它工作正常.
如果List是可滚动的,那么使用此代码不会访问非可见项.如何遍历所有可见+不可见项目的列表项.
for(int i=0;i<list.getCount;i++)
{
View v = list.getChildAt(i);
TextView tv= (TextView) v.findViewById(R.id.item);
Log.d("","ListItem :"+tv.getText());
}
Run Code Online (Sandbox Code Playgroud) 我想开发一个传真应用程序.我在谷歌搜索并找到一些链接,在android上开发传真应用程序的应用程序.但我想使用Android的本机应用程序开发应用程序.在一些网站我读过免费的网络服务可用于发送/使用Android移动应用程序接收传真.但由于安全原因,我不想使用第三方服务.是否提供了任何原生应用程序?否则请告诉我哪种方式更好地开发应用程序?
在我的应用程序中,我编写了用于连接到URL的代码,如下所示
InputStream inputStream = new URL(url).openStream();
Run Code Online (Sandbox Code Playgroud)
我收到了错误.我发送了我的logcat
12-17 15:06:55.065: WARN/System.err(4952): java.net.SocketException: The operation timed out
12-17 15:06:55.065: WARN/System.err(4952): at org.apache.harmony.luni.platform.OSNetworkSystem.connectStreamWithTimeoutSocketImpl(Native Method)
12-17 15:06:55.065: WARN/System.err(4952): at org.apache.harmony.luni.platform.OSNetworkSystem.connect(OSNetworkSystem.java:115)
12-17 15:06:55.065: WARN/System.err(4952): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:244)
12-17 15:06:55.075: WARN/System.err(4952): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:533)
12-17 15:06:55.075: WARN/System.err(4952): at java.net.Socket.connect(Socket.java:1055)
12-17 15:06:55.075: WARN/System.err(4952): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:62)
12-17 15:06:55.075: WARN/System.err(4952): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:88)
12-17 15:06:55.075: WARN/System.err(4952): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHTTPConnection(HttpURLConnectionImpl.java:927)
12-17 15:06:55.085: WARN/System.err(4952): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:909)
12-17 15:06:55.085: WARN/System.err(4952): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:1152)
12-17 15:06:55.085: WARN/System.err(4952): at java.net.URL.openStream(URL.java:653)
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题呢
我已经为onClick
另一个视图的自定义对话框顶部编写了代码.它给了我nullpointer exception
.我也尝试过使用Layout inflater.它给了我错误ok.setOnclickListener
.我的代码有什么问题?
ImageButton search =(ImageButton) findViewById(R.id.search);
search.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Dialog searchDialog = new Dialog(Page.this);
/*LayoutInflater inflater = (LayoutInflater) getApplicationContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.search, null);
searchDialog.addContentView(layout, new LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
searchDialog.setContentView(layout);*/
searchDialog.setContentView(R.layout.search);
searchDialog.setTitle("Search Dialog");
searchDialog.setCancelable(true);
Button ok = (Button)findViewById(R.id.OkButton);
ok.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String searchString = null;
EditText searchText = (EditText)findViewById(R.id.searchText);
if(searchText.getText()!=null){
searchString = searchText.getText().toString();
}
Log.i("TAG","Search word :"+searchString);
}
});
searchDialog.show(); …
Run Code Online (Sandbox Code Playgroud) 从 Assets/sb/example/simple.html/ 下的文件读取时,它给出了 filenotfound 异常。
11-01 18:30:13.562: WARN/System.err(912): java.io.FileNotFoundException: file:///android_asset/sb/example/simple.html
Run Code Online (Sandbox Code Playgroud)
代码片段是
try {
final AssetManager assetMgr = ctx.getResources().getAssets();
is = assetMgr.open(path, AssetManager.ACCESS_STREAMING);
// is = getAssets().open(file.getAbsolutePath());
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud) 我通过使用下面的代码片段从OnItemClickListener获取Checkbox
onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.w("TAG","onItemClick clicked position :"+position);
CheckBox cbx = (CheckBox)view.findViewById(R.id.c_checkbox);
if(cbx.isChecked()){
Toast.makeText(getApplicationContext(),
"Checked position " + shoppingList.get(position).getItem(),
Toast.LENGTH_SHORT).show();
}
Run Code Online (Sandbox Code Playgroud)
我需要获取所有位置以检查哪个列表项被选中.为此我在下面使用了代码片段
int firstPosition = list.getFirstVisiblePosition();
for(int i=firstPosition;i<=list.getCount();i++){
View v=list.getChildAt(i);
cbx = (CheckBox)v.findViewById(R.id.c_checkbox);
if(cbx.isChecked()){
}
}
Run Code Online (Sandbox Code Playgroud)
在下面的代码cbx给我空指针exception.i使用ViewHolder为自定义适配器.请给我解决方案.为什么同样的事情在OnItemClickListener工作?
此致,Rajendar
我为一个应用程序编写了代码.在那里我编写了IME_ACTION_DONE用于编辑文本.所有其他设备都支持这个动作但是在HTC中我没有得到这个'完成'的软键盘按钮.我怎样才能在HTC中获得这个软按钮欲望其他明智的请给我替代EditText上的这个完成按钮功能,而我的应用程序中没有很多更改用于HTC.