我正在尝试将图像以及有关该图像的其他一些信息上传到 PHP 页面,以便 PHP 页面知道如何处理它。目前,我正在使用它:
URL url = new URL("http://www.tagverse.us/upload.php?authcode="+WEB_ACCESS_CODE+"&description="+description+"&userid="+userId);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
OutputStream os = connection.getOutputStream();
InputStream is = mContext.getContentResolver().openInputStream(uri);
BufferedInputStream bis = new BufferedInputStream(is);
int totalBytes = bis.available();
for(int i = 0; i < totalBytes; i++) {
os.write(bis.read());
}
os.close();
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String serverResponse = "";
String response = "";
while((response = reader.readLine()) != null) {
serverResponse = serverResponse + response;
}
reader.close();
bis.close();
Run Code Online (Sandbox Code Playgroud)
除了 GET/POST 混合之外,还有更优雅的解决方案吗?我觉得这似乎很草率,但据我所知,这是一个完全可以接受的解决方案。如果有更好的方法来做到这一点,我会很感激被指出正确的方向。谢谢!
PS:我熟悉您在正常情况下如何通过 POST 与 PHP …
所以我给用户控件使用搜索栏来改变MapView中圆形覆盖对象的半径.
但是,当您拖动搜索条以更改圆的半径时,只有其底部部分会平滑更新:

上半部分是什么,圆的半径是,底部是在圆的半径是目前.底部部分平滑更新(以及搜索栏上的进度),但顶部保持静止半秒左右.
以前见过这样的事吗?这是我正在使用的RadiusOverlay对象的onDraw方法:
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
super.draw(canvas, mapView, shadow);
Point point = new Point();
Projection projection = mapView.getProjection();
projection.toPixels(mGeoPoint, point);
float projectedRadius = projection.metersToEquatorPixels((float)(mRadius * 1609.3d));
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL);
paint.setARGB(50, 41, 166, 247);
paint.setAntiAlias(true);
canvas.drawCircle((float)point.x, (float)point.y, projectedRadius, paint);
}
Run Code Online (Sandbox Code Playgroud)
谢谢你看看.
所以我将我的Android应用程序移植到Kindle,并期望对兼容性进行一些调整,但这太荒谬了.
我发现的第一件事是,如果你也从onCreate()初始化你的布局,显然从onCreate()运行AsyncTask可能会导致一些问题.这在普通的Android中绝对不是这样,但是我在Kindle上获得的最终结果是我的布局部分根本没有显示.将AsyncTask移动到onStart解决了这个问题,但这有点令人惊讶.我仍然有一个问题,即调用此AsyncTask.
此AsyncTask的目的是从在线加载数据并将结果显示在活动的布局中.非常简单,至少在普通的Android设备上.只需在doInBackground中加载数据,然后在onPostExecute中将数据应用到UI以构建页面.
但是,在某些情况下(并非所有),AsyncTask中的数据似乎不会显示在屏幕上.例如,某些数据显示在GridView中.我更新GridView适配器,使用适配器的notifyDataSetChanged()方法,应该发生的是视图被更改为显示来自适配器的数据.普通Android设备上的此过程运行正常.
然而,在这个Kindle上数据没有加载(在某些情况下,并非全部,这使得这更令人沮丧).我发现如果按下Kindle上的后退按钮,然后将手指从它上面移开(因此不会调用finish()),数据有时会显示出来!我觉得对于Kindle的Android版本,notifyDataSetChanged()的正常行为已被改变,但我不确定我还希望将其他数据加载到适配器中.
有没有人遇到过这个问题?
此外,我应该注意,它有时只发生,实际的数据结构保持不变,但对于某些页面它可以工作而其他页面没有(应用程序属于音乐,所以例如一个艺术家的页面正确加载而另一个才不是).
我已经包含了AsyncTask,它可以在任何Android设备上完美运行,所以我不知道它会有什么用处,但无论如何它仍然存在:
private class GetAttendees extends AsyncTask<Void, Void, AttendeesSectionData> {
@Override
protected AttendeesSectionData doInBackground(Void... params) {
JsonHandler jsonHandler = new JsonHandler(getApplicationContext());
return jsonHandler.getEventAttendeesFromFb(mEvent.getFacebookEventId(), JsonHandler.FACEBOOK_FRIENDS_NO_LIKES);
}
@Override
protected void onPostExecute(AttendeesSectionData data) {
if(data != null && !data.isEmpty()) {
if(data.size() > 18) {
ArrayList<String> toShow = new ArrayList<String>();
int friendLimit = data.getFriendsAttendingIds().size();
if(friendLimit > 18)
friendLimit = 18;
for(int i = 0; i < friendLimit; i++)
toShow.add(data.getFriendsAttendingIds().get(i).getImageURL());
int toShowSizeAfterFriends = toShow.size();
if(toShowSizeAfterFriends < 18) {
int …Run Code Online (Sandbox Code Playgroud) 
单击更多图标(固定在列表项右侧的3个垂直点)将打开Google音乐中的上下文菜单:

我正在尝试使用我猜测的上下文菜单来重新创建它.文件说:
如果您的活动使用ListView或GridView并且您希望每个项目都提供相同的上下文菜单,请通过将ListView或GridView传递给registerForContextMenu()来注册上下文菜单的所有项目.
但我仍然希望列表项本身可以点击.我只想在用户点击更多图标时显示上下文菜单,就像在Google音乐中一样.
所以我尝试了这个:
@Override
public void onMoreClicked(ArtistsListItem item, int position, View imageButton) {
registerForContextMenu(imageButton);
}
Run Code Online (Sandbox Code Playgroud)
onMoreClicked只是我从列表的适配器接收onClick回调的自定义侦听器的一部分.
调用registerForContextMenu,但从不调用片段的onCreateContextMenu方法:
@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo info) { //this method is never called
super.onCreateContextMenu(menu, view, info);
android.view.MenuInflater inflater = mActivity.getMenuInflater();
inflater.inflate(R.menu.artist_list_menu, menu);
}
Run Code Online (Sandbox Code Playgroud)
我运行了一些断点来检查它是否正在运行,但它从未这样做过.我对活动的onCreateContextMenu做了同样的事情(registerForContextMenu的类是片段,但只是为了确保我这样做)并且也没有骰子.
我正在使用ActionBarSherlock,我不知道这是否有所作为,但我想这值得注意.
有谁知道这里发生了什么?
我正在尝试为用户创建一种在手机上创建帐户的方法,该帐户最终会通过应用程序同步到他们的联系人.我现在正在模拟器中工作,所以我要去Menu-Dev Tools-AccountsTester来测试我拥有的东西.当我单击AccountsTester时,我在LogCat中收到以下错误代码:
03-08 18:58:31.996: ERROR/AndroidRuntime(403): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.development/com.android.development.AccountsTester}: android.content.res.Resources$NotFoundException: String resource ID #0x0
03-08 18:58:31.996: ERROR/AndroidRuntime(403): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
03-08 18:58:31.996: ERROR/AndroidRuntime(403): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
03-08 18:58:31.996: ERROR/AndroidRuntime(403): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-08 18:58:31.996: ERROR/AndroidRuntime(403): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
03-08 18:58:31.996: ERROR/AndroidRuntime(403): at android.os.Handler.dispatchMessage(Handler.java:99)
03-08 18:58:31.996: ERROR/AndroidRuntime(403): at android.os.Looper.loop(Looper.java:123)
03-08 18:58:31.996: ERROR/AndroidRuntime(403): at android.app.ActivityThread.main(ActivityThread.java:3647)
03-08 18:58:31.996: ERROR/AndroidRuntime(403): at java.lang.reflect.Method.invokeNative(Native Method)
03-08 18:58:31.996: ERROR/AndroidRuntime(403): at java.lang.reflect.Method.invoke(Method.java:507)
03-08 18:58:31.996: ERROR/AndroidRuntime(403): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-08 18:58:31.996: ERROR/AndroidRuntime(403): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-08 18:58:31.996: ERROR/AndroidRuntime(403): at dalvik.system.NativeStart.main(Native Method)
03-08 18:58:31.996: …Run Code Online (Sandbox Code Playgroud) 我正在将rvm/ruby安装到ubuntu 12.04上,但我遇到了一个问题.
rvm成功安装,但之后当我尝试这样做时,rvm install ruby我得到了这个输出:
RVM requires 'curl'. Install 'curl' first and try again.
Warning, new version of rvm available '', you are using older version '1.24.7'.
You can disable this warning with: echo rvm_autoupdate_flag=0 >> ~/.rvmrc
You can enable auto-update with: echo rvm_autoupdate_flag=2 >> ~/.rvmrc
/usr/local/rvm/scripts/functions/utility_system: line 21: awk: command not found
/usr/local/rvm/scripts/functions/utility_system: line 22: dpkg: command not found
/usr/local/rvm/scripts/functions/utility_system: line 191: tr: command not found
/usr/local/rvm/scripts/functions/utility: line 210: head: command not found
/usr/local/rvm/scripts/functions/utility: line 204: sort: …Run Code Online (Sandbox Code Playgroud) 我想在我的一些应用程序样式中设置项目高程.现在海拔只有21和更高,没有支持库,所以我的自然倾向是创建一个样式-v21 xml并将其放在那里:
<style name="Widget.MyApp.Drawer" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:elevation">4dp</item>
</style>
Run Code Online (Sandbox Code Playgroud)
这个问题是我对常规styles.xml文件中的Widget.MyApp.Drawer所做的任何更改都将被完全覆盖.我想要的是将高程添加到我为styles.xml中列出的此样式的v21版本所做的样式更改列表的底部.
所以我开始创建基本样式,我在视图中使用的样式继承自:
<style name="BaseListElement">
<item name="android:background">@drawable/listitem_background</item>
<item name="android:layout_height">@dimen/list_item_height</item>
</style>
<style name="BaseListElement.ListItem">
</style>
Run Code Online (Sandbox Code Playgroud)
我在styles.xml中将样式留空,在styles-v21中,我添加了高程并且它有效.
但是,当我想使用一些高级样式时,这会变得有点棘手:
<style name="BaseListElement">
<item name="android:background">@drawable/listitem_background</item>
<item name="android:layout_height">@dimen/list_item_height</item>
</style>
<style name="BaseListElement.BaseItem">
<item name="android:padding">@dimen/list_item_padding</item>
</style>
<style name="Widget.MyApp.ListItem" parent="@style/BaseListElement.BaseItem">
</style>
<style name="BaseListElement.BaseHeader">
</style>
Run Code Online (Sandbox Code Playgroud)
在这种情况下,BaseItem只是一种从BaseListElement继承的样式,BaseHeader等样式也从它继承.你可以看到,这有点荒谬.
我是否想过这个?我看到它的方式我有三个选择:
1)继续原样,感觉像个白痴
2)在BaseListElement级别上,创建一个带有一些愚蠢名称的子样式,这个名称是我应用高程的点,然后(希望)逐渐渗透到所有孩子.然而,只要基地的v21孩子之间有区别,这就不行了.
3)只需要android:elevation插入styles.xml文件(不要使用v21文件)并在元素上放置一个ignore标志.我这里只有5.0个设备,所以如果这会导致旧版本崩溃,我现在无法轻松测试.
有什么想法吗?
我有一个togglebutton,它没有响应我的setChecked(...)方法.这是代码:
mBool = mPrefs.getBoolean("buttondefault", true);
Boolean b = mBool; //Only creating this for Logging, mBool IS PRIMITIVE
Log.e("Update pref", b.toString());
mToggle = (ToggleButton)findViewById(R.id.ac_toggle);
mToggle.setOnClickListener(this);
mToggle.setChecked(mBool);
Run Code Online (Sandbox Code Playgroud)
日志报告mBool为true,当我mToggle.setChecked(mBool)按下时按钮保持在关闭位置.
这是按钮的xml:
<ToggleButton android:id="@+id/ac_toggle"
android:textOn="Yes"
android:textOff="No"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3sp"
android:layout_weight="5"/>
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我将首先解释我的目标:我希望用户查询数据库,并且仅当这些行自上次查询后已更新时才返回行.没有意义返回他们已经拥有的数据.所以我创建了一个名为'lastupdated'的列,这是一种时间戳类型,每次更新行中的任何内容时都会自动更新.这很好用.现在,我想正确地形成查询.用户将保存其先前查询的时间戳,并通过php将其用于将其先前查询的时间与每行更新的时间进行比较.如果行在上次查询后更新,则应返回该行.
我做了这样的事,
SELECT * FROM users WHERE '2011-02-26 01:50:30' <= lastupdated
Run Code Online (Sandbox Code Playgroud)
但它显然太简单了.我检查了MySQL手册,发现这个页面有MySQL时间/日期页面.我确定答案就在这里,但我已经读过它,没有什么是真正有意义的.我有一个MySQL时间戳类型使用的相同格式的时间戳,但我不知道如何比较它们.非常感谢您的帮助.
我在整个应用程序中使用了一个主题,在主题中文本颜色简单地声明如下:
android:textColor="@android:color/black"
对于位于活动内部的TextView,颜色应用得很好.但是,当我在列表项内部创建一个TextView(由适配器充气)时,文本颜色为白色.
有谁知道需要在主题中声明要影响列表项的样式?
列表项的完整XML:
<CheckBox
android:id="@+id/lt_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"/>
<TextView
android:id="@+id/lt_length"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@id/lt_checkbox"
android:textSize="24dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="8dp"
android:layout_centerVertical="true"
android:layout_toLeftOf="@id/lt_length"
android:layout_alignParentLeft="true"
android:orientation="vertical">
<TextView
android:id="@+id/lt_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:textSize="18dp"/>
<TextView
android:id="@+id/lt_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14dp"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
列表的XML:
<ListView
android:id="@+id/altl_list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Run Code Online (Sandbox Code Playgroud)
和适配器:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LocalTrack track = getItem(position);
ItemHolder holder;
if(convertView == null || convertView.getTag() == null) {
convertView = mInflater.inflate(R.layout.listem_track, parent, false);
holder = new ItemHolder();
holder.title = …Run Code Online (Sandbox Code Playgroud) android ×8
php ×2
android-maps ×1
curl ×1
file-upload ×1
kindle-fire ×1
mysql ×1
ruby ×1
rvm ×1
togglebutton ×1
ubuntu ×1