android-resources

Is it possible to read a raw text file without Context reference in an Android library project

隐身守侯 提交于 2019-12-18 20:04:39
问题 I could put a text file in folder res\raw of a library project, but reading it seems to require a Context reference. Could anyone shed some light on this? 回答1: Check out my answer here to see how to read file from POJO. Generally, the res folder should be automatically added into project build path by ADT plugin. suppose you have a test.txt stored under res/raw folder, to read it without android.content.Context: String file = "raw/test.txt"; // res/raw/test.txt also work. InputStream in =

Easiest way to know (programmatically) which resources folder is used based on screen density/size

时光毁灭记忆、已成空白 提交于 2019-12-18 16:46:27
问题 Is there a way to know exactly which layout (and other resources) are chosen by Android during runtime based on screen density and size when supporting multiple screens? I need to know the folder's name. EDIT: I need to know the folder's name programmatically . 回答1: If you're just doing this for debugging purposes, I'd recommend doing something like this: For each qualifier that you have a layout/drawable for, have a values folder with the same qualifier (e.g. if you have a layout-hdpi, also

Android test raw resource

 ̄綄美尐妖づ 提交于 2019-12-18 13:53:10
问题 I have the following folder structure in Android Studio: ├── androidTest │ ├── java │ └── res │ └── raw │ └── test_file └── main ├── java └── res └── raw └── app_file I'm trying to access the test_file resource which exists in the raw folder of the androidTest elements. Here's the code inside a Robotium test case that inherits from ActivityInstrumentationTestCase2 : InputStream is = this.getInstrumentation() .getContext() .getResources() .openRawResource(R.raw.test_file); Android Studio

Automatic string resources translate

人盡茶涼 提交于 2019-12-18 13:31:38
问题 When I run Android Lint check, I always get errors on my strings resource. The error says that I didn't translate my strings to all the languages. Assuming there are no people who know all the languages ​​in the world (if there are I'm not one of them), and that error has a realistic solution. How can I fix this problem? Is there any way to do it automatically (like with Google Translate)? The error is "<the-string-name>" is not translated in af, am, ar, be, bg, ca, cs, da, de, el, en-rGB, es

Android resource for a specific product

痴心易碎 提交于 2019-12-18 13:08:11
问题 i got this code from Settings app... <string name="about_settings" product="tablet">About tablet</string> <string name="about_settings" product="default">About phone</string> then my questions are: from where at runtime the system load the correct string resource ? What must I do to add a new product? e.g. <string name="about_settings" product="laptop">About laptop</string> 回答1: from where at runtime the system load the correct string resource ? The system does not load this at runtime. The

How to add string in int? R.string.name+Integer.parse(myindex). not working

非 Y 不嫁゛ 提交于 2019-12-18 09:37:48
问题 How to add string in int? R.string.name+Integer.parse(myindex). not working.Link txtt.setText(getString(R.string.("i" + j++))); not helpful. others found 回答1: you can use getIdentifier() to retrieve the string's id, it returns a resource identifier for the given resource name. int stringId = getResources().getIdentifier("name"+myIndex, "string", getPackageName()); if (stringId > 0) { textView.setText(stringId); } if you are looking for a String array, the syntax is slightly different: int

android.content.res.Resources$NotFoundException: Resource ID #0x7f07007e

╄→гoц情女王★ 提交于 2019-12-18 08:09:39
问题 I am Trying to implement like feature in the app, here is the snippet from the Viewholder in the recycled view. Recycler customadapter public class PostAdapterViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { TextView title,user,description,tag,time,designation; Long date; ImageView imageView,bookmark,profilepic,sharebutton,like; RelativeLayout head; LinearLayout content; DatabaseReference reference; Context context; String name; public void setContext(Context

issue in string array in xml file: Multiple substitutions specified in non-positional format and Found tag </item> where </string-array> is expected [duplicate]

怎甘沉沦 提交于 2019-12-18 03:53:48
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Android XML Percent Symbol hi mate i have an array in file xml: <string-array name="type_data_graph"> <item>Veichle speed (Km/h)</item> <item>Engine Rpm (rpm)</item> <item>Barometric pressure (kPa absolute)</item> <item>Fuel pressure (kPa)</item> <item>Fuel Rail pressure of manifold vacuum (kPa)</item> <item>Fuel Rail pressure diesel/gasoline (kPa)</item> <item>MAF air flow rate (grams/sec)</item> <item>Intake

How to get FileInputStream to File in assets folder

旧巷老猫 提交于 2019-12-18 02:46:31
问题 I know how to use the AssetManager to read a File from the res/raw directory with an InputStream , but for my special use case I need a FileInputStream . The reason I need a FileInputStream specifically is because I need to get the FileChannel object from it by calling getChannel() . This is the code I have so far, it reads the data (in my case a list of primitives) from a File : public static int[] loadByMappedBuffer(Context context, String filename) throws IOException{ FileInputStream fis =

Android dynamic String Resources

眉间皱痕 提交于 2019-12-17 19:05:29
问题 in my app I do a web request that returns some result code, e.g. 105. I have string resources that look like that <string name="r105">O.K.</string> <string name="r106">Something went wrong.</string> <string name="r333">Fatal error.</string> Now I want to do something like that Toast.makeText(parent.getApplicationContext(), parent.getString(R.string.r+resultCode), Toast.LENGTH_LONG).show(); while r+resultCode is the resource identifier. This does not work. Any idea how to do that? 回答1: Try