我打算创建一个适用于Android,iPhone和Blackberry的跨平台应用程序?我想过使用Phonegap或Titanium.我的问题如下:
我有一个listview并实现onclick和onfling.problem是当我做fling(从左向右滑动),listview的onclick事件也正在执行.如何解决这个问题?如何区分listview中的触摸(点击)和投掷(滑动)?
listClickListener = new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,int position, long id) {
//Job of Onclick Listener
}
};
mContactList.setOnItemClickListener(listClickListener);
mContactList.setAdapter(adapter);
// Gesture detection
gestureDetector = new GestureDetector(new MyGestureDetector(prosNos));
gestureListener = new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
return true;
}
return false;
}
};
mContactList.setOnTouchListener(gestureListener);
}
public class MyGestureDetector extends SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
// My fling event
return …Run Code Online (Sandbox Code Playgroud) 我想开发HTML5网站.我已经安装了Java for Android开发.我的机器上安装了Eclipse Classic 3.6.现在我希望在同一台机器上安装Java EE.可能吗?如果是这样,请告诉我如何将Eclipse Classic 3.6升级到Java EE开发环境.
嗨我必须在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) 我使用视图来显示动态arrayadapter.it工作但我滚动列表时显示的数据不规则变化.我希望我的列表视图只能填充一次,而不是所有的时间我滚动我的列表.有什么建议吗?这是我的代码
public View getView(int position, View convertView, ViewGroup parent) {
// A ViewHolder keeps references to children views to avoid unneccessary calls
// to findViewById() on each row.
ViewHolder holder;
// When convertView is not null, we can reuse it directly, there is no need
// to reinflate it. We only inflate a new View when the convertView supplied
// by ListView is null.
if (convertView == null) {
convertView = mInflater.inflate(R.layout.sample, null);
// Creates a ViewHolder and …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Android添加联系人getContentResolver.首先我创建了一个ArrayList:
ArrayList<ContentProviderOperation> ops =
new ArrayList<ContentProviderOperation>();
Run Code Online (Sandbox Code Playgroud)
然后填充数组列表
int rawContactInsertIndex = ops.size();
ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME,accountName)
.build());
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID,rawContactInsertIndex)
.withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, name)
.build());
Run Code Online (Sandbox Code Playgroud)
最后是一个试块
getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
Run Code Online (Sandbox Code Playgroud)
当我执行此操作时,我没有收到任何错误或异常.但该联系人不会出现在Android联系人中.当我检索隐形联系人时,我可以找到这个联系人.谁能弄清楚出了什么问题?
似乎android日历api不可用.你能不能给我一些创建类似东西的提示和技巧.就像创建活动,会议,生日等......以及事件发生时的通知.并且布局应该类似于 - 我们的内置日历给我一些关于外观和逻辑的想法或提示?
我正在尝试将自定义视图添加到操作栏中.
final View addView=getLayoutInflater().inflate(R.layout.home_actionbar_buttons, null);
getActionBar().setCustomView(addView);
Run Code Online (Sandbox Code Playgroud)
我的XML,
<LinearLayout android:id="@+id/linearLayout1"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:layout_width="match_parent">
<Button android:text="Refresh" android:layout_height="wrap_content"
android:id="@+id/btn_refresh" android:layout_width="wrap_content"></Button>
</LinearLayout
Run Code Online (Sandbox Code Playgroud)
但我得到nullpointer异常.当我调试时,addView对象被填充,而不是null.在充气时,ViewGroupRoot是强制性的吗?
编辑1:Logcat
09-30 12:50:11.625: DEBUG/PackageManager(74): Activities: com.example.actionbar.MainActivity
09-30 12:50:11.645: INFO/ActivityManager(74): Force stopping package com.example.actionbar uid=10047
09-30 12:50:11.825: INFO/installd(34): move /data/dalvik-cache/data@app@com.example.actionbar-1.apk@classes.dex -> /data/dalvik-cache/data@app@com.example.actionbar-1.apk@classes.dex
09-30 12:50:11.825: DEBUG/PackageManager(74): New package installed in /data/app/com.example.actionbar-1.apk
09-30 12:50:12.215: DEBUG/PackageManager(74): generateServicesMap(android.accounts.AccountAuthenticator): 3 services unchanged
09-30 12:50:12.306: DEBUG/PackageManager(74): generateServicesMap(android.content.SyncAdapter): 5 services unchanged
09-30 12:50:12.475: WARN/RecognitionManagerService(74): no available voice recognition services found
09-30 12:50:12.605: DEBUG/dalvikvm(143): GC_EXPLICIT freed 2K, 17% free 14616K/17415K, …Run Code Online (Sandbox Code Playgroud) android nullpointerexception android-custom-view android-button android-actionbar
我正在尝试以编程方式在Android中添加联系人.这是我的代码:
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
int rawContactInsertIndex = ops.size();
ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE,"Google")
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME,"user1@gmail.com") .build());
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(Data.RAW_CONTACT_ID,rawContactInsertIndex)
.withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, name)
.build());
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, rawContactInsertIndex)
.withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, phone)
.withValue(ContactsContract.CommonDataKinds.Phone.TYPE, phoneType)
.build());
ops.add(ContentProviderOperation.newInsert(ContactsContract
.Data.CONTENT_URI)
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID,rawContactInsertIndex)
.withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.Email.DATA, email)
.withValue(ContactsContract.CommonDataKinds.Email.TYPE, emailType)
.build());
try {
getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
Context ctx = getApplicationContext();
CharSequence txt = "Contact " + name +" added successfully";
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(ctx, txt, duration);
toast.show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(),"error",Toast.LENGTH_LONG).show();
}
Run Code Online (Sandbox Code Playgroud)
我这样做了吗?如何添加帐户名称和帐户类型?
注意:我没有创建任何帐户.是否必须拥有帐户才能添加联系人?
我有一个Listof HashMap,它具有 type 的键和 type 的Integer值Long。
List<HashMap<Integer, Long>> ListofHash = new ArrayList<HashMap<Integer, Long>>();
for (int i = 0; i < 10; i++) {
HashMap<Integer, Long> mMap = new HashMap<Integer, Long>();
mMap.put(Integer.valueOf(i), Long.valueOf(100000000000L+i));
ListofHash.add(mMap);
}
Run Code Online (Sandbox Code Playgroud)
现在,如何从 的列表中检索键和值HashMap?
如果使用Collection类是解决方案,请启发我。
更新 1:
实际上我是从数据库中获取值并将其放入 HashMap
public static List<Map<Integer, Long>> populateMyHashMapFromDB()
{
List<HashMap<Integer, Long>> ListofHash = new ArrayList<HashMap<Integer, Long>>();
for (int i = 0; i < 10; i++) {
HashMap<Integer, Long> mMap = new …Run Code Online (Sandbox Code Playgroud)