我是Android编程的总菜鸟,想学习如何调试我的应用程序.我似乎无法在LogCat中显示我的Log.i | d | v调用.
这是我正在使用的代码.正如您所看到的,我已经定义了一个LOG_TAG常量,但似乎无法在LogCat中找到它.我还导入了android.util.Log并确保在我的AndroidManifest中我将"debuggable"设置为TRUE.
我还检查了http://developer.android.com/reference/android/util/Log.html没有运气解决这个问题.
我究竟做错了什么?我甚至在正确的地方寻找?我已经尝试过使用DDMS和Debug透视图,但没有运气.任何帮助这个菜鸟将不胜感激.谢谢.
我的环境:Windows XP IDE = Eclipse版本:3.6.1,构建ID:M20100909-0800 Emulator =指向android sdk 2.1 api 7
//非常基本的HELLO World代码,带有几个Log.i调用
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class debugger extends Activity {
private static final String LOG_TAG = "debugger";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
Log.i(LOG_TAG, "line 13");
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.i(LOG_TAG, "CREATING NOW");
}
}
Run Code Online (Sandbox Code Playgroud) 我ListView创建了一个Android ,SimpleAdapter其中包含的项目多于屏幕中的项目.滚动列表后,我需要获取列表中第一个可见项的数据模型中的位置.
基本上我想要一个像:listView.getChildAt(0).getPositionInDataModel().
Adapter它有一些功能getItemId(position),看起来很有用; 但是,SimpleAdapter实现只返回传入的位置,而不是像我希望的那样的行ID.
一个强力解决方案是在索引0处获取View,并将其与适配器中每个项目的视图进行比较.但是,似乎没有一种简单的方法可以从适配器获取特定位置的视图.
有人有什么想法?
我在我的String.xml文件中定义了一个使用格式参数的字符串,即:
<string name="myString">Hello %1$s.</string>
Run Code Online (Sandbox Code Playgroud)
有没有办法为布局xml文件中的format参数赋值?我有类似的东西:
<TextView android:text="@string/myString"/>
Run Code Online (Sandbox Code Playgroud)
我知道我可以在java中做到这一点,但有没有办法在这里做到这一点?
谢谢!
我有一个Android应用程序,当它运行服务时,我想在状态栏上显示通知.然后用户可以通过按HOME键导航到其他应用程序.但是,当我尝试通过通知图标将之前运行的应用程序恢复到Front时,现有活动存在一些问题.即使我将其声明为"单顶"模式(我想运行现有的活动,因为有关联的服务正在运行),不知何故,在OnResume之前已经调用了活动的OnDestroy.这是我创建通知对象的代码.你能指点我错了吗?谢谢.
private void showNotification ()
{
Intent toLaunch = new Intent(getApplicationContext(),
MySingleTopActivity.class);
PendingIntent intentBack = PendingIntent.getActivity(getApplicationContext(), 0,toLaunch, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(getApplicationContext(),
getText(R.string.GPS_service_name), text, intentBack);
....
}
Run Code Online (Sandbox Code Playgroud) 有没有办法将文件上传到其他用户的Google云端硬盘,而不是每次都要求登录或验证码,除了第一次?
到现在为止我使用了pydrive,但它每次都要求登录.除此之外还有其它方法,例如用一键还是用来跳过用户的登录?
有人可以给我一些链接/教程来使用存储在SD卡上的SQLite文件吗?没有实现OpenHandler.
/ SD CARD // info.db.
我想使用外部SQlite数据库文件(不使用Android内部数据存储),因为我想经常更新数据库文件,以提供有关info.db的更多最新信息.
谢谢.
我有一个PreferenceActivity2级树的PreferenceScreens,类似于:
<PreferenceScreen>
<PreferenceScreen android:key="A">
<ListPreference/>
<EditTextPreference/>
</PreferenceScreen>
<PreferenceScreen android:key="B">
<ListPreference/>
<EditTextPreference/>
</PreferenceScreen>
...
</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)
每个较低级别的偏好屏幕,例如A和B,正在收集两个相关的数据.我希望这些父项的摘要是两个子首选项的当前值的组合.
我尝试在叶子首选项上添加onPreferenceChangeListener并从那里更新摘要,但似乎没有.首选项都是在活动中以编程方式创建的,所以我在onCreate中做了类似的事情:
leafListPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
// do some work
prefScreenA.setSummary( /* get new summary based on newValue */);
return true;
}
});
Run Code Online (Sandbox Code Playgroud)
然后我试图找到一个位置,我可以通知我已经从子页面返回到顶级首选项屏幕,以便我可以在此时更新.但是,我对如何显示下级屏幕感到困惑.看起来它们实际上是对话框,而不是完整的活动,因为onPause/onResume在它们之间移动时不会被调用.在返回顶级页面时,是否有一些我遗漏的方法会被调用?
我也尝试添加一个sharedPreferenceChangeListener,如所描述这里,但似乎从来没有被调用.
任何人都对我在这里缺少的东西有任何暗示,或者我错过的任何更简单的方法?
当我在API描述中检查getSharedPreferences(String,int)时,Second属性定义了可访问性模式,默认操作可以采用0或MODE_PRIVATE,MODE_WORLD_READABLE和MODE_WORLD_WRITEABLE可以控制权限.
但是在API描述中有一个小注:
注意:目前这个类(android.content.SharedPreferences)不支持跨多个进程使用.这将在稍后添加.
此外,在Mark L. Murphy的书"开始Android 2"中他提到:
(最终,首选项可能在应用程序之间共享,但截至撰写本文时尚不支持)
我很困惑!这是否意味着getSharedPrefrences的MODE_WORLD_READABLE和MODE_WORLD_WRITEABLE是有,但不是在最新的API级别尚不支持???
谢谢!米泔
我正在尝试创建一个简单的基于Spring的Web服务,它支持带有xml内容的"帖子".
在Spring中,我定义了一个AnnotationMethodHandler:
<bean id="inboundMessageAdapter" class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<util:list>
<bean class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
<property name="marshaller" ref="xmlMarshaller"/>
<property name="unmarshaller" ref="xmlMarshaller"/>
</bean>
</util:list>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
和一个基于jaxb的xml marshaller:
<bean id="xmlMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="contextPaths">
<array>
<value>com.company.schema</value>
</array>
</property>
<property name="schemas">
<array>
<value>classpath:core.xsd</value>
</array>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
我的控制器注释如下,其中"Resource"是由jaxb自动生成的类:
@RequestMapping(method = POST, value = "/resource")
public Resource createResource(@RequestBody Resource resource) {
// do work
}
Run Code Online (Sandbox Code Playgroud)
Web服务调用的结果始终为"HTTP/1.1 415 Unsupported Media Type".这是一个示例服务调用:
HttpPost post = new HttpPost(uri);
post.addHeader("Accept", "application/xml");
post.addHeader("Content-Type", "application/xml");
StringEntity entity = new StringEntity(request, "UTF-8");
entity.setContentType("application/xml");
post.setEntity(entity);
Run Code Online (Sandbox Code Playgroud)
在我看来,我正在设置正确的媒体类型.有人有想法吗?
编辑:在进一步调试之后,它看起来好像从未尝试解组该对象.我不太了解AnnotationMethodHandler如何知道application/xml类型应该发送到MarshallingHttpConverter背后的黑魔法.任何人都可以对此有所了解吗?
我的WebView没有填满手机的整个宽度.我告诉fill_parent.不知道为什么?
<?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="fill_parent"
android:orientation="horizontal">
<WebView android:layout_height="fill_parent" android:layout_width="fill_parent" android:id="@+id/WebView"></WebView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)