我有这个包含我的JSON索引的ConstantData类,我需要在带有额外内容的活动之间传递它们.但在此之前,我必须首先将Parcelable实现到此类的对象.
我的问题是,如何在我的类中声明对象并将每个对象放在变量中?
我是新手,我现在完全无能为力.谢谢.随意修改我的代码如下.
ConstantData.java
public class ConstantData{
public static String project_title = "project title";
public static String organization_title = "organization title";
public static String keyword = "keyword";
public static String short_code = "short code";
public static String project_description = "description";
public static String smallImageUrl = "smallImageUrl";
public static String bigImageUrl = "bigImageUrl";
public static String price= "price";
public static String country= "country";
public static ArrayList<Project> projectsList = new ArrayList<Project>();
public int describeContents() {
return 0;
}
public void writeToParcel(Parcel out, …Run Code Online (Sandbox Code Playgroud) 我曾经拥有这种简单的JSON数据,我可以成功地解析属性并将它们保存到SQLite数据库中.
[
{
"project_title" : " ",
"organization_title" : " ",
"website": "",
"address": "",
"keyword" : "",
"short_code" : "",
"project_description" : "",
"smallImageUrl" : "",
"bigImageUrl" : "",
"price" : "",
"country" : "",
"donationAmount" : "",
"categories" : "",
"campaign_id" : "",
"currency_isoname": "",
"paypal_email" : "",
"elv_available" : ""
}
]
Run Code Online (Sandbox Code Playgroud)
但现在我有一个更复杂的JSON文件:
[
{
"location": {
"deleted_at": "null",
"documentary_video_length": "81",
"id": "15",
"latitude": "52.4134145988286",
"longitude": "13.0904620846177",
"position": "5",
"updated_at": "2011-08-26T15:30:27+02:00",
"name": "Glienicker Br\u00fccke",
"text": "",
"documentary_video_url": …Run Code Online (Sandbox Code Playgroud) 我正在构建一个从Web下载图像并将它们存储到我的SD卡中的应用程序,为了使它们在库中不可见,我将这一行生成一个.nomedia文件:
FileWriter f = new FileWriter("/sdcard/Android/data/CopyImage/cache/.nomedia");
Run Code Online (Sandbox Code Playgroud)
应用程序可以成功下载图像并将.nodata文件放在同一个文件夹中,但事实是,图像仍然出现在图库中.
怎么会这样?任何人都可以为我提供解决方案吗?
非常感谢你
我有一个普通的按钮,但文字被截断了.我不知道为什么会这样.
谁能分析一下它为什么会发生?
码:
<TextView
android:id="@+id/txt_project_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Default Title"
android:textColor="@android:color/white"
android:textStyle="bold"
android:textSize="19sp"
android:shadowColor="#000000"
android:shadowDx="1.5"
android:shadowDy="1.5"
android:shadowRadius="1"
/></LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/whitebg"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:orientation="vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
>
<ImageView
android:id="@+id/project_image"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_weight="3"
android:layout_gravity="center_vertical"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="10dp"
android:layout_weight="5"
>
<TextView
android:id="@+id/txt_project"
android:layout_width="181dp"
android:layout_height="wrap_content"
android:text="Project Title"
android:textColor="#0e3946"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="@+id/txt_organization_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Organization Title"
android:textSize="13sp"
android:textStyle="italic"
android:textColor="#20822c"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" …Run Code Online (Sandbox Code Playgroud) 我有这个方法,可以从正常活动调用:
getBaseContext().getResources().updateConfiguration(config2, getBaseContext().getResources().getDisplayMetrics());
Run Code Online (Sandbox Code Playgroud)
问题是我不能getBaseContext()在Fragment中调用,我该怎么做?或者我需要getBaseContext()从Fragment类中替换什么?
我正在寻找没有GPL许可证的Android版PDF查看器库,有没有人知道是否有任何可用的免费许可证库?
因为我一直在漫游,并发现一些开源库,如MuPDF,Android PDF Viewer,DroidReader正在使用GPL许可证,我不能用于我即将开发的商业应用程序.
不,我也不想使用谷歌文档选项;-)
我想使用此NameValuePair方法从我的Android客户端向Web服务器发送几个值:
public void postData() {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http:/xxxxxxx");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
String amount = paymentAmount.getText().toString();
String email = inputEmail.getText().toString();
nameValuePairs.add(new BasicNameValuePair("donationAmount", amount));
nameValuePairs.add(new BasicNameValuePair("email", email));
nameValuePairs.add(new BasicNameValuePair("paymentMethod", "5"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// …Run Code Online (Sandbox Code Playgroud) 我有一个自定义ListView适配器,它实现了ImageThreadLoader类.不幸的是,该类没有启用缓存选项 - 从Web下载图像并将其保存为缓存.
然后我发现这个LazyList或者这里非常有用,它的行为与我的ImageThreadLoader类完全相同,但它能够将图像保存为缓存.所以,我想将其ImageLoader类实现到我当前的自定义ListView适配器.
不幸的是,我的代码和Lazylist的结构完全不同,导致我的尝试出现了一些冲突.例如,LazyList使用图像URL的字符串数组,另一方面我使用JSON作为图像URL的源.
这就是为什么我需要一个帮助来使我的ListView适配器适应这个ImageLoader类.
以下是代码:
ImageLoader类,我希望实现到我的自定义ListView适配器:
public class ImageLoader {
//the simplest in-memory cache implementation. This should be replaced with something like SoftReference or BitmapOptions.inPurgeable(since 1.6)
private HashMap<String, Bitmap> cache=new HashMap<String, Bitmap>();
private File cacheDir;
public ImageLoader(Context context){
//Make the background thead low priority. This way it will not affect the UI performance
photoLoaderThread.setPriority(Thread.NORM_PRIORITY-1);
//Find the dir to save cached images
if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
cacheDir=new File(android.os.Environment.getExternalStorageDirectory(),"Android/data/LazyList");
else
cacheDir=context.getCacheDir();
if(!cacheDir.exists())
cacheDir.mkdirs();
}
final int stub_id=R.drawable.stub;
public …Run Code Online (Sandbox Code Playgroud) 我在我的应用程序上为TextView使用自定义字体/自定义字体.TextView显示文本的一个段落,但是与字体本身的额外行间距相当令人恼火.因此段落上的一行与另一行之间存在相当大的差距.任何人都可以知道如何通过XML或以编程方式减少间距?
我使用此XML布局在我的活动上显示全屏VideoView.视频是全屏但不居中.在横向模式下,它停留在屏幕的左侧,并在屏幕的右侧留下一些空白区域.
如何将我的VideoView置于屏幕中央?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<VideoView android:id="@+id/myvideoview"
android:layout_width="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_height="fill_parent">
</VideoView>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)