Edit .xml using simple requests - android

What I need to do is, give the app into hands of a non-programmer and make it simple for him to edit the xml and java files. To do that I thought maybe sending a simple request (such as, add product(name, description, price)) through some portal could edit the xml file and java file. For example, I need to repeat the similar code every time a new product request is posted:
activity_main.xml
<LinearLayout
android:id="#+id/hw5"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="10dp"
android:clickable="true"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:src="#mipmap/ic_launcher"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hardware 5"
android:textColor="#000000"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="$-"/>
</LinearLayout>
MainActivity.java
LinearLayout hw5;
hw5 = (LinearLayout) findViewById(R.id.hw5);
hw5.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent hw5 = new Intent(MainActivity.this, Hw5.class);
startActivity(hw5);
}
});
Thanks!

What you might be looking for here is a domain-specific XML file paired with an appropriate XSL transformation. The XML file that the non-technical person would be editing would define the business entities, relationships with them and potential actions performed on them. The XSL transformation would convert this into application code at build time.
While this is not a common approach, it is rather robust. Keep in mind tho, that such an approach is difficult to maintain and requires that your business logic is mature enough before implementation.

Related

Android studio throws "Too much output to process error" on debug

Android studio throws "Too much output to process error" on debug.
I just started working on android development and trying to debug using my nexus 5 as a connected device.
Being a novice, I thought it was a memory issue and even closed all the background applications. In my single activity I am just displaying a background image and a button.
Please have a look at the layout xml...
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/backgroundimage"
android:weightSum="5"
android:orientation="vertical">
<LinearLayout
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_weight="1"
android:background="#C9BDBD"
android:padding="5dp">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="20dp"
android:background="#6C7B8B"
android:textColor="#000000"
android:text="Become An Android Developer"
android:onClick="Congratulations!!! You are now initiated.."/>
</LinearLayout>
your Button's android:onClick should be a method in the Java code.
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="20dp"
android:background="#6C7B8B"
android:textColor="#000000"
android:text="Become An Android Developer"
android:onClick="Congratulations!!! You are now initiated.."/>
something like
android:onClick="doSomthing"/>
and in the Java code:
public void doSomthing(View v){
...
...
...
}
As far as "too much output..." issue is concerned, you can mostly ignore it. Still it would make sense if you remove some of the really unnecessary Log lines from your code, especially from methods that are called repeatedly and frequently.
Another thing, i believe you want to show a text "Congratulations!!! You are now initiated.." when user clicks on button.
So change your xml's android:onClick to android:onClick= "myButtonClicked"
In the activity, implement this function
public void myButtonClicked(){
}
Finally, show the text "Congratulations!!! You are now initiated.." either via dialog (e.g. alertDialog) or in some textView
You may have selected "No Filters" in android monitor which causes "Too much output to process error", Change it to "Show only selected Application" then all other Log line are filtered and will not show in Logcat.

Automatically Generating java code for xml layout in Eclipse

I have got an idea to get rid of some coding when we do initializion of views.
When we create an xml layout in android. At that movement same name class is created with UpperCase Letters with a dialogue with permission. And as i created views with ids. It should create Views and initialize them automatically.
for e.g
close.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" >
<Button
android:id="#+id/closeBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/close_img" />
<TextView
android:id="#+id/closeText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Testing Text" />
</LinearLayout>
And automatically generated java code should be.
public class Close extends Activity
{
TextView CloseText;
Button CloseBtn;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CloseText = (TextView)findViewById(R.id.closeText);
CloseBtn = (Button)findViewById(R.id.closeBtn);
}
}
I can read xml and do the other stuff as I explained. But how could i add this module to eclipse and How could i create a service which work in Background all the time in eclipse.
Suggest me how to add this module(Plugin) to eclipse and i am going to use JAXB to generate Java Objects from XML document. Is there any better option.
Here in this website i find that just paste the xml and you will get your java code ready for activity class.
i had attached the link

Getting all checkboxes, radio buttons, ratings from an expandable list view: android

I have an expandable list view that houses a short survey (3-4 fields for a user to insert data about) per record that we have. Then we have a button that they can hit to submit the data to our server. When they hit the button I need it to grab all the data in the surveys and send it to our site. I have the sending portion of it figured out; what I'm struggling with is grabbing all the data from the survey.
I've looked through many of the related posts/google results and attempted to implement and adapt their solution for listviews to expandedlistviews but I have not been able to get any of them working. I've spent quite a few hours trying to get some workable solution but alas, I cannot figure it out.
I think part of my problem is I'm not exactly certain how children views come into play for expandable list views. In any event below is my code in hopes that someone smarter than me can help me solve this problem.
So I have my ExpandableListView fragment_survey.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
tools:context="edu.ucr.aum.fragments.SurveyFragment$PlaceholderFragment">
<ExpandableListView
android:id="#+id/list_view_survey_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/rowPaddingMedium"
android:layout_marginRight="#dimen/rowPaddingMedium"
android:divider="#null"
android:dividerHeight="0dp"
android:clipToPadding="false"
android:scrollbarStyle="outsideOverlay" />
<TextView
android:id="#+id/tvResponseCode"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/list_view_survey_list"
android:text="Response Code: "/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Submit Survey"
android:layout_below="#+id/tvResponseCode"
android:id="#+id/btnSubmitSurvey" />
</RelativeLayout>
And here is my row xml list_view_survey_row.xml:
<TextView
android:id="#+id/tvSurveyTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/surveyTitle" />
<TextView
android:id="#+id/tvSurveyShared"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="#string/surveyShared"
android:layout_below="#+id/tvSurveyTitle"
/>
<RadioGroup
android:id="#+id/radioShared"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/tvSurveyShared">
<RadioButton
android:id="#+id/radioButtonYes"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/yes"
android:focusable="true"/>
<RadioButton
android:id="#+id/radioButtonNo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/no"
android:focusable="true"/>
</RadioGroup>
<TextView
android:id="#+id/tvSurveyReason"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/surveyReason"
android:layout_below="#+id/radioShared" />
<TextView
android:id="#+id/tvSurveyRating"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="#string/surveyRating"
android:layout_below="#+id/tvSurveyReason" />
<CheckBox
android:id="#+id/checkBoxInterest"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/surveyInterestPositive"
android:layout_below="#+id/tvSurveyRating"
android:focusable="true" />
<CheckBox
android:id="#+id/checkBoxPrivacy"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/surveyShareLevelPositive"
android:layout_below="#+id/checkBoxInterest"
android:focusable="true" />
<RatingBar
android:id="#+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/checkBoxPrivacy"
android:focusable="true" />
<View android:layout_width="fill_parent"
android:layout_height="2dip"
android:background="#FF00FF00"
android:layout_below="#+id/ratingBar" />
Then I have a fragment (fragment_survey.java) which adds an onclicklistener to the button (btnSubmitSurvey) in the fragment_survey.xml file. That onClickListener() function calls two methods (one to get the data and one to send that data).
this.buttonSubmit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
getData(v);submitSurvey();
}
});
public void getData(View view) {
//get data here
}
public void submitSurvey() {
// Create a new HttpClient and Post Header
String url;
if(Singletons.Debug.debug) {
url = "url for postback";
} else {
url = "url for postback";
}
NetworkAsyncTask nat = new NetworkAsyncTask();
try {
String response = nat.execute(url).get();
//Log.d(TAG, "Response: " + response);
} catch(ExecutionException e) {
} catch(InterruptedException e) {
}
}
You should create a data structure like an array to store the survey data, I would index it by group and/or child position, whatever makes sense for the data. Then you should add listeners for each question input, when a question is answered yes, add into that data structure the answer at the appropriate location. Then when you press the submit button it can iterate over that data structure, prompt for unanswered questions or fill out default values, gather it all together and then submit.
Basically there's no easy/built in way to access the individual rows of your dynamic/reusable rows that I have been able to find. When the context of which row is important I've found the best way is to have my own data structure that uses the group/child position to find which button is being pressed since every row has a button with the same id. I also store the group position/index in the button using setHint on creation so that in the context of the listener i can determine the position.
I had to do this via a horrific hack-job, but it works. I added a button for each row that will allow the user to "save" the row. When they save the row then the data is saved to my data structure. Unfortunately to get this working properly I had to create a custom OnClickListener which takes the view as an argument and from there I can scrape the elements from the view.
It's not an elegant or good solution; but it works.

Gradle: No resource identifier found for attribute 'android.onClick' in package 'android

I just installed the new Android Studio and am having some trouble as I follow the android developer training guide (http://developer.android.com/training/index.html).
Each time I try to compile my code, I receive this error
"Gradle: No resource identifier found for attribute 'android.onClick' in package 'android'"
My initial search resulted in me checking my API level and capitalization of onClick (neither of which seem to be the issue) ((I also understand that using onClick is not best practice, but I am simply following the guide at this point))
Since receiving this error, I have tried manually reinstalling gradle.
Does anyone know what my issue is?
Also, code:
<?xml version="1.0" encoding="utf-8"?>
<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="horizontal" >
<EditText android:id="#+id/edit_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="#+string/edit_message" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_send"
android:android.onClick="sendMessage" />
</LinearLayout>
I suggest not to add button click listeners this way.
Button Click Listeners in Android
Check this out for more details. you can find plenty of resources on how to add buttons.
Generally i find it a good practice to add them through code as opposed to XML
try android:onClick="sendMessage"
In Activity, implement method public void sendMessage(View view);
You should add id to your view widget, and identify these views by id.
I agreed with DArkO. I had the same issue with Android Studio. When I use OnClickListener on my code, the issue has gone away.
On Activity.xml
<Button android:id="#+id/message_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_send"
/>
On Activity.java
Button button = (Button) findViewById(R.id.message_button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
sendMessage();
}
});

Android;Body of ProgressDialog?

I saw this source as layout of AlertDialog in res\layout folder of Android SDK:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout android:id="#+id/body"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:paddingLeft="8dip"
android:paddingTop="10dip"
android:paddingRight="8dip"
android:paddingBottom="10dip">
<ProgressBar android:id="#android:id/progress"
style="#android:style/Widget.ProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:max="10000"
android:layout_marginRight="12dip" />
<TextView android:id="#+id/message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
</LinearLayout>
</FrameLayout>
I tried to find TextView that it's id is "message" like this:
TextView tvMessage = (TextView)dialog.findViewById(android.R.id.message);
It works fine.Then I tried to find LinearLayout that it's id is "body" like this:
LinearLayout body = (LinearLayout)dialog.findViewById(android.R.id.body);
But eclipse show this error:
body cannot be resolved or is not a field
This is snippet code:
ProgressDialog dialog = new ProgressDialog(WriteOpinionActivity.this);
dialog.setMessage("some text");
dialog.show();
TextView tvMessage = (TextView)dialog.findViewById(android.R.id.message);
LinearLayout body = (LinearLayout)dialog.findViewById(android.R.id.body);
Why this error occurs and how I can reach "body"?
Basically, not all resources are accessible to You from platforms res folder.
E.g. I'm able to find #+id/message in global_actions_item.xml, usb_storage_activity.xml, alert_dialog_holo.xml, js_prompt.xml, progress_dialog_holo.xml, progress_dialog.xml, alert_dialog.xml (for API 17), and so, there's no warranty that You get id which defined in progress_dialog.xml (it can be defined in another file and just because of the same name You is able to find it in progress dialog).
Actually, public resources are defined here, however, it looks quite outdated, so some resources might be missed. Checkout these questions about lists of all accessible resources: 1 and 2
Use this instead.
TextView tvMessage = (TextView)dialog.findViewById(R.id.message);
LinearLayout body = (LinearLayout)dialog.findViewById(R.id.body);
You weren't actually using android.R.id.message in the first place. #+id/message means you are creating a new id resource named message.
To use an id that exists in the Android framework, you can see here that you use #android:id/progress. And in source, you use it like you had it: android.R.id.progress.
Otherwise, use android:id="#=id/myIdentifier" in XML and
findViewById(R.id.myIdentifier) in code.
http://developer.android.com/guide/topics/resources/overview.html

Categories

Resources