我从一个交换ResourceCursorAdapter我曾经newView和bindView一个SimpleCursorAdapter在那里我只使用getView方法.
现在我有一个错误onLoaderFinished.虽然它给了我NullPointerException在adapter.swapCursor(cursor)我的两个适配器和光标对象是NOT NULL.我将在下面发布我的所有代码.非常感谢任何帮助(没有多余的头发留下来).
import android.annotation.SuppressLint;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.widget.ResourceCursorAdapter;
import android.util.Log;
import android.util.SparseBooleanArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.CheckBox;
import android.widget.ListView;
import android.widget.TextView;
public class ContactSelect extends FragmentActivity implements LoaderManager.LoaderCallbacks<Cursor> {
private static final int LOADER_ID = 1;
private MyAdapter …Run Code Online (Sandbox Code Playgroud) android nullpointerexception android-listview android-cursorloader
(更新)这适用于模拟器,但不适用于我的HTC图例:(
我的ListActivity中有以下方法,并且它没有返回Cursor中的任何值(getCount = 0)
我无法理解为什么.我在列表中点击哪个联系人并不重要.
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
Log.d(TAG,"onListItemClick");
//get Telephone number for entry and display in Toast
Uri phoneUri = ContentUris.withAppendedId(Phone.CONTENT_URI, id);
Log.d(TAG,String.valueOf(phoneUri));
String[] projection = new String[]{Phone.NUMBER};
//Get Cursor
Cursor phoneCursor = managedQuery(phoneUri, projection, null, null, null);
while(phoneCursor.moveToNext()){
String dspNumber;
String number = phoneCursor.getString(phoneCursor.getColumnIndexOrThrow(Phone.NUMBER));
if(number==""){
dspNumber = "No number found";
}else{
dspNumber = number;
}
Toast.makeText(this,dspNumber, 3000).show();
}
}
Run Code Online (Sandbox Code Playgroud) 希望有人能帮忙解决这个问题......
我下载了SmartSVN并在其中打开了一个工作副本(Android项目).它要我将工作副本升级到1.8.
这使我在使用svn客户端时没有任何问题.但是我确实需要升级我的命令行svn客户端(运行OSX Yosemite).
现在,当我在命令行输入svn --version时,它指向1.8版本......奖金!
但是,在Android Studio中,当我运行assembleProductionRelease时,我有一个运行svn info和extras版本号的阶段.
这是代码
def getSvnRevision() {
new ByteArrayOutputStream().withStream { os ->
def result = exec {
executable = 'svn'
args = ['info']
standardOutput = os
}
def outputAsString = os.toString()
def matchLastChangedRev = outputAsString =~ /Last Changed Rev: (\d+)/
return "${matchLastChangedRev[0][1]}"
}
}
Run Code Online (Sandbox Code Playgroud)
这不再运行和报告;
svn:E155021:此客户端太旧,无法使用xxx的工作副本
编辑我还修改了首选项 - >版本控制 - > Subversion中的路径,它被称为"使用命令行客户端",指向正确路径中的svn文件.
我还在Android工作室中使缓存无效,看看是否有帮助,仍然没有运气.
我试图在工具栏中使用setTitle和自定义视图显示标题.
我不把它当作动作栏,而只是视图.
我在Java中添加标题和自定义视图
toolbar = (Toolbar) view.findViewById(R.id.toolbar);
if (title != null) {
toolbar.setTitle(title);
toolbar.setTitleTextColor(getResources().getColor(android.R.color.white));
}
if (subtitle != null) {
toolbar.setSubtitle(subtitle);
toolbar.setSubtitleTextColor(getResources().getColor(android.R.color.white));
}
// Add switch view to toolbar
View switchView = LayoutInflater.from(getActivity())
.inflate(R.layout.device_list_switch, null);
toolbar.addView(switchView);
Run Code Online (Sandbox Code Playgroud)
我的交换机视图的xml是
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/holo_blue_bright">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/discoverable"
android:layout_alignParentBottom="true"
android:layout_alignTop="@+id/discoverable"
android:layout_toLeftOf="@+id/discoverable"
android:layout_toStartOf="@+id/discoverable"
android:gravity="center"
android:text="@string/discoverable_switch_label"
android:textColor="@android:color/white"
/>
<Switch
android:id="@+id/discoverable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginLeft="@dimen/discoverable_switch_margin_left"
android:layout_marginStart="@dimen/discoverable_switch_margin_left"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
会发生的是RelativeLayout填充整个工具栏区域并且标题不可见.
有任何想法吗?
我想制作一个让用户选择主题并将其应用于整个应用程序的应用程序.
我知道这可以通过在每个活动的onCreate中使用setTheme来实现.
但我需要以不同的方式工作.我不希望主题存储在theme.xml或styles.xml中.
我希望有一个存储在网络上的主题列表,并能够动态下载新主题并将其应用到应用程序中.我希望能够创建新主题,而无需构建新版本或更新版本的应用程序.
图像很容易替换.只需从网址下载并在本地存储即可重复使用.但是应用程序的实际主题,按钮的颜色等应该在运行时从theme.xml文件更改,该文件不是apk的一部分,而是在线获取.
这可能吗?
我已经发布了现有应用程序,我想将位置coords字段添加到sqlite数据库.
我想知道是否可以在不在数据库中创建新表的情况下执行此操作.我不想覆盖用户现有的数据库条目,我只想为现有的数据库条目添加这个新字段并给它一个默认值.
这可能吗?
我已经复制并粘贴了本网站上的Form stuff示例中的代码.当我尝试运行项目时,我收到一个错误,项目有一个带有白色十字的红色正方形但是当深入到项目的元素(使用eclipse)时,有一个错误的元素.在Eclipse的问题选项卡中,我有以下文字
描述资源路径位置类型Unparsed aapt错误!检查控制台输出.HelloFormStuff2未知的Android打包问题
但控制台里什么都没有!! 这是我正在使用的代码和元素......
HelloFormStuff2.java
package com.android.HelloLinearLayouts;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class HelloFormStuff2 extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Perform action on clicks
Toast.makeText(HelloFormStuff2.this,
"Beep Bop",
Toast.LENGTH_SHORT).show();
}
});
}
}
**res/drawable-hdpi/android-button.xml**
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/android_pressed"
android:state_pressed="true"/> …Run Code Online (Sandbox Code Playgroud) 我正在运行Google开发者网站上提供的YouTubeSample.我的代码没有错误,我的导入似乎没问题.但是当我运行项目时,我得到了上述错误.
我做了一些搜索,但说实话,我一直无法解决问题所在.我已经尝试进口外部罐番石榴但它没有帮助.
任何帮助表示赞赏.这是完整的课程
package com.pengilleys.googlesamples;
import java.io.IOException;
import java.util.List;
import com.google.api.client.googleapis.GoogleHeaders;
import com.google.api.client.googleapis.json.JsonCParser;
import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpRequestFactory;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson.JacksonFactory;
import com.google.api.client.util.Key;
public class YouTubeSample {
public static class VideoFeed {
@Key List<Video> items;
}
public static class Video {
@Key String title;
@Key String description;
@Key Player player;
}
public static class Player {
@Key("default") String defaultUrl;
}
public static class YouTubeUrl extends GenericUrl {
@Key final String alt = …Run Code Online (Sandbox Code Playgroud) 我正在努力研究如果我可以使用资源文件,在开发我的Android应用程序时,使用字符串值作为键来保存数字列表.例如
数字("英国")= 999数字("美国")= 911
正如我所说,理想情况下,这将是资源文件而不是Java类,因为它更易于维护
我正在建立一个活动,我希望填充有电话号码的联系人.
我没有使用Intent,因为我希望在listview中的每个联系人之前都有一个复选框.
我正在使用CursorLoader.以下是onCreateLoader方法的一些代码;
String projection[] = new String[]{ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME};
Uri uri = ContactsContract.Data.CONTENT_URI;
String selection = ContactsContract.Contacts.HAS_PHONE_NUMBER + "=1" +
" AND " + ContactsContract.Contacts.IN_VISIBLE_GROUP + " =1";
String order = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
CursorLoader loader = new CursorLoader(this, uri, projection, selection, null, order);
Run Code Online (Sandbox Code Playgroud)
我在我的ListView中使用了ResourceCursorAdapter的子类.
有没有人有任何想法我如何删除重复?除非我真的需要,否则我不想使用Set.
我需要以编程方式更改操作栏标题文本颜色.
我使用以下代码以稍微不同的方式设置颜色,具体取决于SDK版本
int textColor = getResources().getColor(android.R.color.white);
if (Build.VERSION.SDK_INT >= 14) {
// Version 4+
int titleId = getResources().getIdentifier("action_bar_title", "id", "android");
TextView abTitle = (TextView) findViewById(titleId);
if (abTitle != null) {
abTitle.setTextColor(textColor);
}
} else {
// Other versions
TextView abTitle = (TextView) getWindow().findViewById(android.R.id.title);
if (abTitle != null) {
abTitle.setTextColor(textColor);
}
}
Run Code Online (Sandbox Code Playgroud)
它适用于SDK值为14或更高的设备.但是,对于Gingerbread设备,abTitle始终为null,因此颜色不会设置.
anyony有什么建议吗?