嗨我必须在listview中添加一个手势,我想实现联系人应用程序的相同功能.当我离开滑动它应该发送一条消息,右键滑动它应该打电话.任何人都可以帮助我如何做这些手势检测...我已经在各种其他视图中实现了...但我不能为listView做...我不知道什么去了...我的代码是`
/** Called when the activity is first created. */
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
// Create an array of Strings, that will be put to our ListActivity
String[] names = new String[] { "Linux", "Windows7", "Eclipse", "Suse", "Ubuntu", "Solaris", "Android", "iPhone"};
// Create an ArrayAdapter, that will actually make the Strings above
// appear in the ListView
this.setListAdapter(new ArrayAdapter<String>(this, R.id.MyList, names));
gestureListener = new ListView.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
return …
Run Code Online (Sandbox Code Playgroud) 我有以下ListActivity:
public class ShowDayActivity extends ListActivity implements OnItemClickListener {
private GestureDetector gestureDetector;
private View.OnTouchListener gestureListener;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.day);
registerForContextMenu(getListView());
gestureDetector = new GestureDetector(new MyGestureDetector());
gestureListener = new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
};
getListView().setOnItemClickListener(this);
getListView().setOnTouchListener(gestureListener);
}
@SuppressWarnings("static-access")
@Override
public boolean onOptionsItemSelected(MenuItem item) {
...
return super.onOptionsItemSelected(item);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
...
return super.onContextItemSelected(item);
}
Override
public void onItemClick(AdapterView<?> parent, View v, int pos, long …
Run Code Online (Sandbox Code Playgroud) 我遇到了许多人似乎从PHP中遇到的同样问题,缺乏一个体面且易于使用的关联数组解决方案.我在这里阅读了一些基本上都建议使用HashMap的问题,比如Q:Java associative-array
但是,我认为所提到的解决方案不会解决我的问题.我会解释一下.
我有一个包含250个项目(国家/地区)的列表,我想要存储数据.数据长度未定义,这意味着它可以为每个"列"保留多个条目,有时没有条目,有时是4,等等.
在PHP中,我可以这样做:
$country_data = new array();
$country_data["nl"]["currency"] = "euro";
$country_data["nl"]["languages"] = "Dutch";
...
$country_data["us"]["currency"] = "US dollar";
$country_data["us"]["languages"] = array("English", "Spanish");
Run Code Online (Sandbox Code Playgroud)
所以有时我想存储一个数组,有时候不是.当然,它也可以是只有一个条目而不是字符串的数组,但我只是说.
所以,问题是,如何在HashMap中的数组中存储和获取数组?我知道我几乎坚持使用丑陋的HashMap解决方案,但我仍然无法看到这将如何让我存储数组,我敢肯定我会忽略一些简单的事情.基于我的一个例子会很棒!
UPDATE
我选择使用HashMaps的HashMaps原因我需要能够轻松监督所有内容,并在需要时更改几行值.这很灵活,我可以轻松地根据国家/地区代码,语言获取国家/地区名称,或者我可以在需要时获取country_data HashMap,或者所有国家/地区名称等等.
public class iso_countries {
Map<String, Object> country_data = new HashMap<String, Object>();
Map<String, String> country_name = new HashMap<String, String>();
Map<String, String[]> country_idd = new HashMap<String, String[]>();
Map<String, String[]> country_cid = new HashMap<String, String[]>();
public iso_countries(){
country_name.put("nl", "Netherlands");
country_idd.put("nl", new String[]{"+31"});
country_cid.put("nl", new String[]{"#31#", "*31#"});
setData(country_name, country_cid, country_idd);
// 249 * 4 …
Run Code Online (Sandbox Code Playgroud) 我一直试图使用以下方法删除服务设置的持久通知:
startForeground(1337, notification);
Run Code Online (Sandbox Code Playgroud)
我用来取消它的代码:
NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nManager.cancel(1337); // cancel existing service notification, doesn't take effect
nManager.cancelAll(); //surpluous, but also doesn't take effect
Run Code Online (Sandbox Code Playgroud)
为了澄清我为什么这样做:服务以默认的持久性通知开始.当我的应用运行时,它需要将此通知替换为另一个.notify()
然而,使用现有的通知工作非常完美,我还需要它来显示新通知的滚动条文本.这就是为什么我决定删除现有的通知(使用上面的代码),创建一个新的,然后我startForeground()
再次调用并将新的通知传递给它,所以我的服务仍然存在.
android foreground android-service notificationmanager android-notifications
我正在开发一个需要Google帐户才能使用某些选项的应用程序.当没有检测到帐户时,选项被禁用,但我通过弹出提示用户添加一个,如果用户单击是,则应该开始活动.它可以正常显示全局"添加帐户"页面,但我想跳过那个不需要的额外步骤.毕竟,如果需要Google帐户,为什么要向某人提供添加Exchange帐户的选项,这只是令人困惑.所以我想默认使用新的Google帐户设置页面.
Java的
try {
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClassName( "com.google.android.gsf", "com.google.android.gsf.login.AccountIntroActivity");
//if(getApplicationContext().getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) != null) {
getApplicationContext().startActivity(intent);
//} else {
//getApplicationContext().startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
//}
} catch ( ActivityNotFoundException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
当我运行它时,抛出以下异常:
05-29 18:24:50.741:W/System.err(10875):android.content.ActivityNotFoundException:无法找到显式活动类{com.google.android.gsf/com.google.android.gsf.login.AccountIntroActivity }; 你有没有在AndroidManifest.xml中声明这个活动?
AndroidManifest.xml中
<activity
android:name="com.google.android.gsf.login.AccountIntroActivity"/>
Run Code Online (Sandbox Code Playgroud)
问题:我在这里缺少什么?
编辑:
我尝试了使用addAccount的不同方式,这不起作用,没有任何反应,没有错误,没有新活动开始添加Google帐户.顺便说一下,原始版本中的整个try catch块都在AlertDialog/listener中.
AccountManager acm = AccountManager.get();
acm.addAccount("com.google", null, null, null, null, null, null);
Run Code Online (Sandbox Code Playgroud) 我试图使用嵌套的postDelayed,因为我需要在(延迟)5分钟之后做一些事情,在延迟30秒后停止它,做其他事情,然后从开始再次重复循环中的两个事件.我似乎无法做对.
代码我有sofar:
private long EnabledAfter = 300000; // 5 minutes
private long DisabledAfter = 30000; // 30 seconds
public void start_timers(){
on_delayed(EnabledAfter);
}//end method
private void on_delayed(long period_off){
Delayed = new Runnable() {
public void run() {
something.enable(context);
something.enable_else(context, true);
off_delayed(DisabledAfter); // and disable both again delayed
Handler.postDelayed(Delayed, EnabledAfter);
}
};
Handler.postDelayed(Delayed, EnabledAfter);
}//end method
private void off_delayed(long period_on){
Delayed = new Runnable() {
public void run() {
something.disable(context);
something.disable_else(context, false);
on_delayed(period_on); // start the proces again from the start... …
Run Code Online (Sandbox Code Playgroud) 我AsyncTask
在另一个AsyncTask
(2)中使用(1 ).AsyncTask 1获取在线用户数据,计算响应中的条目数以及每个条目,onPostExecute
显示用户名并运行新的AsyncTask(2)以从服务器获取图像并将其加载到ImageView
.这一切都发生在onPostExecute
.这完美地工作,获取并显示用户数据,并且每个条目逐个显示图像.
然而,通过阵列的itteration和的更新TextView
中AsyncTask
1的onPostExecute
情况发生得这么快,它基本上只显示数组中的最后一个用户名,其他的人被加载,但无法与人眼检测:)
同时,AsyncTask
2仍在从网上获取图像,并显示错误用户的个人资料图像.我在这里遇到的问题显然是这两个需要同步.所以我以为我只是等待方法中的输出AsyncTask
2 get()
,但现在根本没有任何更新,不TextView
...这对我来说是意想不到的行为.
那么,问题是如何同步2 AsyncTask
s?
如果仍然需要,可以澄清一些代码
//instantiate first AsyncTask
new AsyncRequest().execute(bundle);
private class AsyncRequest extends AsyncTask<Bundle, Void, String> {
protected String doInBackground(Bundle... bundle) {
String data = null;
try {
data = request(null, bundle[0]); //request the data
return data;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch …
Run Code Online (Sandbox Code Playgroud)