Internal link to TextView in Android? - android

I find myself stuck in something I think would be really easy to solve. My app contains a lot of TextViews and ImageViews, and one TextView contains the content listed. I want each element of the displayed content internally linked to the respective TextView. Probably the TextView isn't the right element to use, but I have trouble finding the right element.
The internal link should work exactly like internal links in html-documents... is this possible to achieve in Android?
strings.xml:
<string name="c3">3. Contents</string>
<string name="c4">1. Abstract
\n3. Contents
\n4. List of Abbreviations
\n5. Introduction
\n6. Materials & Methods
\n6.1 Literature Selection
\n6.2 Method
\n6.3 What is Android?
\n6.3.1 Dalvik Virtual Machine and Android Applications
\n6.3.2 Android Structure, Java and XML
\n6.3.3 Android Versions
\n6.4 The Development Environment
\n6.4.1 Android SDK
\n6.4.2 Eclipse IDE
\n6.4.3 Android Virtual Device
\n6.4.4 Secure Digital Card
\n6.5 “Hello World!” as Test of IDE
\n6.6 Test Application
\n6.7 Developing Strategy
\n7. Result
\n7.1 Facebook Connect
\n7.1.1 Facebook Application
\n7.1.2 Facebook Connect for Android
\n7.2 Networking
\n7.3 Data Synchronization
\n8. Discussion
\n9. Conclusion
\n10. References
\n10.1 Internet References
\n10.2 Lecture References\n\n
</string>
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/smoke"
android:scrollbars="vertical"
>
<ScrollView android:id="#+id/ScrollView01"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:scrollbars="none"
>
<LinearLayout android:id="#+id/LinearLayout02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="4px"
android:paddingRight="4px"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/a"
android:textColor="#color/black"
android:gravity="center_horizontal"
android:textSize="16dp"
android:paddingBottom="2dp"
android:paddingTop="20dp"
android:scrollbars="vertical"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/b"
android:gravity="center_horizontal"
android:textColor="#color/black"
android:scrollbars="vertical"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/c1"
android:textColor="#color/black"
android:textSize="20dp"
android:paddingBottom="2dp"
android:scrollbars="vertical"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/c2"
android:textColor="#color/black"
android:scrollbars="vertical"
/>

If I were you, I'd convert your content into HTML with internal links and use a WebView to display it. I have no idea how you would pull off what you are trying to do any other way. Moreover, that's the typical approach used for ebooks, which appears to be what you are trying to create.

Related

Generate UI from a string [duplicate]

I had lots of research about this issue but I didn't get the answer that I want.
So I do have an application getting string from the server. The series of string is in XML Format.
Here is an example of what I shall get from the server (as you can see it's a layout):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/number_ref" />
<EditText
android:id="#+id/etTxtNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/subject_ref" />
<EditText
android:id="#+id/etTxtSubject"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/body_ref" />
<EditText
android:id="#+id/etTxtBody"
android:layout_width="match_parent"
android:layout_height="200dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/btnTxtSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/save_ref"/>
<Button
android:id="#+id/btnTxtSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/send_ref"/>
<Button
android:id="#+id/btnTxtClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/close_ref"/>
</LinearLayout>
</LinearLayout>
This will be changed depending on what xml file will be uploaded from the server. My problem is how can I implement these series of string into layout and to be loaded as layout of an activity. I was thinking of saving it in an xml file to sdcard of the device and load it as layout but I guess it's not possible to recompile the code after running it. Any suggestions? Thank you.
As explained in the Android documentation, the layout xml files are not used at runtime - they are compiled to binary code at compile time. So, you can't directly load the xml as a Layout.
You'd have to write code that reads the xml, interprets it, and uses Android api methods to create a corresponding View.
Common use cases
If you need to A/B test different UI designs without the need to re-upload your APK.
If your app's UI changes dynamically based on different users or scenarios.
If you need to deploy UI fixes quickly and in real-time.
json2view can help you.
I think now it can be done using the dynamic layout's in android.
https://www.javacodegeeks.com/2012/09/android-dynamic-and-xml-layout.html#:~:text=Android%20activity%20contains%20various%20user,activity%20in%20two%20different%20ways.&text=Basically%2C%20Layout%20file%20is%20xml,file%20present%20in%20res%2Flayout.
https://medium.com/mindorks/creating-dynamic-layouts-in-android-d4008b72f2d

Why is my android app only show up in playstore when using quotation marks "titleOfApp"?

Hello my favorite community.
Maybe someone has the answer out there
I recently put my first app to the play store market and after a couple of hours it appears there. But the thing is the first days i did not recognized that it was already on the market caused by the problem i cant find it. So i taught i need to update it to another version by adding some language support stuff.
After found a hint on this lovely board that some apps will only appear in search query by put the app name into quotation marks. But why is that and do somebody know how i should change the name of the app to get a better search result.
i already changed from Camel Case Notation "myAppTitle" to "my app title" but this was not really a solution for my problem.
moreover i had the same issue like many others with some android devices. my app seems to run on almost 70% of the devices (since android v14) but on some devices that exception raises:
viewrootimpl senduseractionevent() mview == null
some people have same problems almost with samsung devices...an answer i found was that samsung has an special android layer for touch wizard. but how to work arround that problem?
Thanks in advanced.
here an excerpt from the layout which causes this problem..
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/TableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<!-- ROW -->
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.15" >
<TextView
android:id="#+id/textView__game_title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#color/black"
android:gravity="center"
android:text="anyText"
android:textColor="#ffffff"
android:textSize="20sp" />
</TableRow>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:orientation="vertical" >
<TextView
android:id="#+id/textView__game_word1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#color/yellow"
android:gravity="center"
android:onClick="onClick"
android:text="anyText?"
android:textSize="35sp" />
<TextView
android:id="#+id/textView__game_word2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#color/red"
android:gravity="center"
android:onClick="onClick"
android:text="anyText?"
android:textSize="35sp" />
<TextView
android:id="#+id/textView__game_word3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#color/blue"
android:gravity="center"
android:onClick="onClick"
android:text="anytext?"
android:textSize="35sp" />
</LinearLayout>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.15" >
<TextView
android:id="#+id/textView__game_score"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#android:color/black"
android:gravity="center|left"
android:paddingLeft="15dp"
android:text="Score:\n0"
android:textColor="#ffffff"
android:textSize="20sp" />
<TextView
android:id="#+id/textView__game_round"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#android:color/black"
android:gravity="center|right"
android:paddingRight="15dp"
android:text="Round:\n 0 of 100"
android:textColor="#ffffff"
android:textSize="20sp" />
</TableRow>
</TableLayout>
Since you app is new, Google Play will only show top results, that's why you have trouble finding your app. If your app download count have raised to thousand or more, it will more easy to be search by others.
I found a solution for my above explained problems.
First, the layout problem and the message:
"viewrootimpl senduseractionevent() mview == null"
is easily solved by changing the layout to a Linear Layout. Moreover I changed from TextViews to Buttons that solved the issue why my app did not funtcion correctly on 30% of all android devices like samsung galaxy s3 and so on.
These devices had a problem with onClicks on Textviews and therefore by using Buttons the problem was fixed.
The viewrootimpl... is still null but do not have any influence to the behaviour of my app...like in many other post u can just ignore this log output.
Second, the reason why my app is not visible by using the search funtcion in google play market without the use of "myapp title" is the internal ranking of apps made by google.
The ranking of apps in play store depends on different factors. One is the ratings made by users. But one crucial factor is the ranking by keywords used in app title.
If you use frequent used keywords in your app title then your app would be easily found, but if you use an app title which do not contains any keyword, your app will only be found by using quoation marks.
So I changed my app title by adding some keywords at the end and after updating it to the play store, i immediately found my app by using the search function of the market.
Hopefully, this post will help others which struggle with the same problems.
Good Luck

Images does not shown on Mvx.MvxImageView (Android)

I am trying to learn mvvmcross and I am a newbie now. I started to watch N + 1 days of MvvmCross video series and I am stuck at N = 2 Kittens and Lists. I add DownloadCashPlugin and FilePlugin to the project and create Mvx.MvxImageView as shown on the video but when I start my app(both simulator and android device), everything is same but images does not shown or not downloaded. I open permission from android manifest and I have an internet connection on my android device. I am pretty sure I follow videos carefully and dont miss any part.
I am using Visual Studio 2013 Communtiy Edition and MvvmCross is last updated version. I will be glad if anyone can help me on this problem. Thank you.
Item_Kitten.axml ;
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Mvx.MvxImageView
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_margin="10dp"
local:MvxBind="ImageUrl ImageUrl" />
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="40dp"
local:MvxBind="Text Name" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="30dp"
local:MvxBind="Text Price" />
</LinearLayout>
</LinearLayout>

Google tv not displaying complete layout of my android application

I am trying to expand on a basic hello world application for the google tv. I have created a LinearLayout with a EditText and Button within it and put that under a very large 'Hello world' TextView (78sp).
When I launch the application on the google tv box (adb), I get my 'Hello World' but only the very top of the EditText and Button.
Looking at the application within Eclipse Android Layout manager, its all fine and visible.
Any ideas on how to fix this?
I believe I must be missing some configuration element in all of this.
Any help appreciated. Thanks
code, my main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="475dp"
android:gravity="center"
android:text="#string/hello"
android:textSize="78sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/edit_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="#string/edit_message" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_send" />
</LinearLayout>
</LinearLayout>
Probably because your first text view is 475dp high. You can see here that a TV is only 540dp high (remember that an actual pixel and a display independent pixel [dp] are not the same unless the screen is mdpi which no Google TV is)

LinearLayout - How to get text to be on the right of an icon?

Bit of a newbie when it comes to android, only been working on it properly for a few days but even after all the searching I've done im stumped and nobody seems to know how to help me. I have this so far:
http://img263.imageshack.us/i/sellscreen.jpg
How can I move the text to be besides each icon rather than underneath it? Hoping the gallery won't be moved either. Here is the code i have:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scroller"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Gallery xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<ImageView
android:id="#+id/test_image"
android:src="#drawable/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="The offcial UK driving theory test application. Over 190 questions."
/>
<ImageView
android:id="#+id/test_image"
android:src="#drawable/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="The offcial UK driving theory test application. Over 190 questions."/>
<ImageView
android:id="#+id/test_image"
android:src="#drawable/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="The offcial UK driving theory test application. Over 190 questions."/>
<ImageView
android:id="#+id/test_image"
android:src="#drawable/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="The offcial UK driving theory test application. Over 190 questions."/>
<ImageView
android:id="#+id/test_image"
android:src="#drawable/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="The offcial UK driving theory test application. Over 190 questions."
/>
</LinearLayout>
</ScrollView>
Top half of my code doesn't seem to be showing for some reason but it's just the opening of the linear layout.
I will be forever grateful to anyone that can help, i've been racking my brains for days and getting nowhere. Really getting stressed out by it. Thanks in advance!!
You need to wrap each ImageView/TextView pair in a linearlayout
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/test_image"
android:src="#drawable/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="The offcial UK driving theory test application. Over 190 questions."
/>
</LinearLayout>
It's also pretty clear that you didn't ask anyone who knew android, because this is pretty trivial.
Have you read through the android layout tutorials? Lots of stuff on the dev site, like declaring layout, common layout objects, and the hello views tutorials.
There are a number of ways to accomplish this, depending on your goals.
Is it a list of items of unknown size that may want to scroll? Use a ListView. You can provide a custom layout to the ListView with your things side by side.
Do you have a finite set of things? Use a RelativeLayout. Tell each TextView to layout below the one above, and each ImageView to layout to the right of it's TextView.
You could also accomplish that with nested LinearLayouts, one vertical and a bunch of horizontal, but that is less efficient than using a RelativeLayout.

Categories

Resources