and thanks for watching my question.
above, I am not good at english.. but I think all of you could understand my word....
please help me...!!!
In my application, I made 3 scrollview that include linearlayout each other.
And if I click some buttons, then chronometer add in log 1(linearlayout), and other chronometer add in log 2(linearlayout), and some words add in log 3(linearlayout), using add(text).
Finally, Working is done pressing the stop button and same time writing log is ended.
And I want to 2 ways method.
combine log1, log2, log3 data each same row and save a textfile in device storage.
combine log1, log2, log3 data each same row and intent to another activity(name is result)
How can I do this...?
here is my code.. thank you..
//activity_main.xml
<ScrollView
android:id="#+id/scrollview"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="10dp"
app:layout_constraintLeft_toRightOf="#id/title"
app:layout_constraintRight_toLeftOf="#id/itemtimescrollview"
app:layout_constraintTop_toBottomOf="#+id/realtime"
app:layout_constraintBottom_toBottomOf="#id/title">
<LinearLayout
android:id="#+id/layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"></LinearLayout>
// same more 2 linearlayout
//MainActivity.java
//data record to layoutpublic void datarecordtolayout()
{String currentTime = new SimpleDateFormat("HH:mm:ss", Locale.getDefault()).format(new Date());
scrollview = (ScrollView) findViewById(R.id.scrollview);
layout = (LinearLayout) findViewById(R.id.layout);
TextView textview = new TextView(this);
textview.setText(currentTime);
layout.addView(textview, 0);
// same more 2 instance() .. layout(this one), passedlayout(other), commentlayout(the other)
I was using intent.. but I failed..
Related
I was already looking for various navigation solutions but I couldn't fit any for my app.
I have Parcelable objecs which are displayed in ListView using Array Adapter. When i click on item, it goes to another activity with another layout, dedicated to display this single item with image gallery, title etc. Therefore, i would like to add simple navigation as in picture which moves to next item if exist, previous item if exist and back to List View.
Here's some code
Single Item activity
public class SingleItem extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_single_item);
Intent intent = getIntent();
Single singleItem = intent.getParcelableExtra("Single");
String id = singleItem.getId();
Integer position = singleItem.getPosition();
String title = singleItem.getTitle();
String subtitle = singleItem.getSubtitle();
String text = singleItem.getText();
int[] image = singleItem.getImage();
TextView titleTV = findViewById(R.id.singleItemTitle);
LinearLayout gallery = findViewById(R.id.gallery);
LayoutInflater inflater = LayoutInflater.from(this);
for (int i = 0; i < image.length; i++) {
View view = inflater.inflate(R.layout.single_item_gallery, gallery, false);
ImageView imageView = view.findViewById(R.id.singleItemGalleryImage);
imageView.setImageResource(image[i]);
gallery.addView(view);
}
TextView descTV = findViewById(R.id.singleItemDesc);
titleTV.setText(title);
descTV.setText(text);
}
}
Here's my adapter
val listViewAdapter = ItemListAdapter(this, R.layout.adapter_view_layout, itemList)
listView.adapter = listViewAdapter
listView.setOnItemClickListener { _: AdapterView<*>, _: View, position : Int, _: Long ->
val intent = Intent(this, SingleItem::class.java)
intent.putExtra("Single", itemList[position])
startActivity(intent)
}
Single Item layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="#+id/singleItemTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/singleItemTitle">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="220dp"
android:paddingStart="10dp"
android:scrollbars="none"
android:paddingEnd="10dp">
<LinearLayout
android:id="#+id/gallery"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"/>
</HorizontalScrollView>
<TextView
android:id="#+id/singleItemDesc"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
And i would like put navigation in layout above.
List view:
Single item navigation example:
Hello and welcome to StackOverflow (SO)!
As a newcomer you may not be aware, but, on SO, you should clearly define your question. I don't see a direct question. I'm deducing that you need a set of guidance in implementing your image gallery view using Android and to be able to swipe through them using the buttons (if I'm not mistaken).
Your approach is theoretically okay. What's left to do it to get a reference to the Next/Previous buttons from your SingleItem Activity and to manually scroll the HorizontalScrollView object when you press Next/Previous buttons.
However, your code has a major flaw in the following code segment.
for (int i = 0; i < image.length; i++) {
View view = inflater.inflate(R.layout.single_item_gallery, gallery, false);
ImageView imageView = view.findViewById(R.id.singleItemGalleryImage);
imageView.setImageResource(image[i]);
gallery.addView(view);
}
This is something which you should not be doing. Instead, use a RecyclerView which will only load your image when it's required to be displayed. You're essentially creating all the image views once you visit the detail view (SingleItem).
Your current approach might work okay for a few images, but is not recommended for a lot of images as it may
Slow down and freeze the app while the images load
You'll eventually run out of memory
Once you get this implemented with the RecyclerView, give it a shot and see whether it works. If you still have trouble, please don't hesitate to ask!
Cheers!
I see two options:
Instead of putting a whole Parcelable in the intent just put some kind of ID of the object. It can be a primary key, if you store them in DB or just an array index, if it's an array in memory kept in some singleton object. Then in SingleItem activity's onCreate just find the item by ID and load it. Therefore you can open more SingleItem activities from a SingleItem activity just by passing next or previous item ID to it.
Use fragments instead. You'll be having one activity, which holds a reference to the list of items, and two fragments one for the list view one and another for a single item display. Thus in single item fragment you can call a method on parent activity once "Next" button is clicked, which will then take the next item and create a replacement single item fragment with new data.
I'm trying to make Image buttons act like Radio buttons. Let me explain. I have a basic layout containing an Image Button and a TextView, that I load with different images and texts.
XML layout :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:id="#+id/button_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#FFFFFF"/>
<TextView
android:id="#+id/text_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
</LinearLayout>
Java method :
LinearLayout categoryLayout = view.findViewById(R.id.categories_layout);
for (int i = 0; i<categories.size(); i++) {
final String name = categories.get(i).name;
final int resource = categories.get(i).resource;
View v = getLayoutInflater().inflate(R.layout.choose_category, null);
final TextView text = v.findViewById(R.id.text_category);
text.setText(name);
ImageButton button = v.findViewById(R.id.button_category);
button.setImageResource(resource);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
selectedCategory = resource;
text.setTypeface(text.getTypeface(), Typeface.BOLD);
}
});
categoryLayout.addView(v);
}
Every time an image is clicked, the text is set bold to indicate which button was clicked. My problem is that I only want one button to be clickable at a time. I thought of, each time a button is clicked, reseting the appearance of all TextView, only leaving the last text that was clicked as bold. However, I don't know how to navigate through all layouts that have been generated.
I hope I was clear, thank you if you can help me !
That might not be the most efficient way to solve this problem, but it works. Every time the button is clicked, the icon selected is saved. Then, I use removeAllViews() method on the RadioGroup, and recreate the views. I just make sure the text below the previously selected icon is set bold.
I'm new to mobile development and I am having trouble displaying variables as text on to the screen.
public class wifiinfo() {
public string getmac = getBSSID();
}
I have this in my main (blank) activity but I have no clue as to how to code this in with XML. The Android Developer tutorials haven't really helped me. Do I have to index the string in a database, perhaps? Any help would be greatly appreciated.
Use Textview to display text.
Add this in your XML:
<TextView
android:id="#+id/textViewSSID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:hint="Your SSID"/>
And display text in activity like this:
TextView tvSSID = (TextView) findViewById(R.id.textViewSSID);
String ssid = getBSSID();
tvSSID.setText(ssid);
Why you create an inner class to keep the value of ssid is a real mystery to me. You can make the variable getmac as a member variable in the activity and initialize it in your onCreate of your activity.
Update:
As to your comment, your activity should start somewhat like this:
public class ActivityName extends Activity {
private string MacId = null;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_layout);
MacId = getBSSID();
//Other functions
}
You can use TextView to write text and display it on the screen.
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Your text here..."/>
If your text line is so long you should write it in res/values/strings.xml:
<string name="my_text">This is a very long line text I want to show on screen.</string>
And use android:text="#string/my_text" to get it in the TextView.
Hope it helps!
I am facing problem to convert layout .xml files to Java
I fave tried but failed to complete.
I need anyones help to complete it.
Need Help! Thanks in advance.
Here is my layout .xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/lay"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<CheckBox android:id="#+id/checkbox_cheese"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/cheese"
android:onClick="onCheckboxClicked"/>
</LinearLayout>
I just want to convert it to java which i have tried so far:
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.lay);
CheckBox box = new CheckBox(this);
box.setId(c);
/* from here how to convert those below lines in Java
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/cheese"
android:onClick="onCheckboxClicked"
*/
I am in a good mood, or I would have just pointed you to Egor's comment; the tutorials are designed to show you the efficient ways to do what you want.
LinearLayout.LayoutParams boxParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
box.setLayoutParams(boxParams);
box.setText(R.string.cheese);
// if you want checkbox change listener
box.setOnCheckedChangedListener(new OnCheckedChangedListener(){
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (isChecked){
// perform logic
}
}
};
// if you want on click listener functionality
box.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v){
// perform logic
}
}
linearLayout.addView(box);
Haven't tested it, don't know if it is bug free (may have missed something or done something wrong), but I can tell you that unless you plan on only doing this functionality and no other functionality you REALLY need to read into the basics of Android.
android:layout_width="wrap_content"
android:layout_height="wrap_content"
->setLayoutParams(..)
android:text="#string/cheese"
->setText(..)
android:onClick="onCheckboxClicked"
->setOnClickListener(..)
Do something like this:
View layout = ViewInflater.from(this).inflate(R.layout.layout, null); //your layout name
LinearLayout linearLayout = (LinearLayout) layout.findViewById(R.id.lay);
CheckBox box = (CheckBox) layout.findViewById(R.id.checkbox_cheese);
Now the box object will have all the properties assigned in the xml.
I am new to android development and I am troubled with something.
I want to create a user interface first and I have a question regarding adding dynamic fields. I am already using XML to setup my interface but I don't know how to proceed.
For example, the user can select 1 2 3 or 4 and based on the selection I would like the dialog box to show that number of EditText. Also the same thing would apply later. A table would show that number of textviews at the header.
Is there a way to do this by using some XML and some java? Because I believe by using only java it will be a pain to style different things.
Please let me know if you need further info.
Thanks in advance
You should check out the visibility attribute of a View.
If you have a fixed set of ui elements (say, 5 buttons) you can just include them in the layout and show them later with setVisibility(View.Visible).
However, if you have a dynamic amount of elements (the user can chose from 1 to n buttons) then you will have to implement it in Java. You can still use XML layouts for parts of the work, but most stuff will have to be done by hand.
I have written a sample code , See if it helps you
public class ActivityMain extends Activity {
LinearLayout main;
private int id = 0;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
main = (LinearLayout) findViewById(R.id.parent);
main.setOrientation(LinearLayout.VERTICAL);
final EditText editText = (EditText) findViewById(R.id.et_count);
Button button = (Button) findViewById(R.id.btn);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
final int count = Integer.parseInt(editText.getText()
.toString());
addEditText(count);
}
});
}
private void addEditText(int count) {
for (int i = 0; i < count; i++) {
LinearLayout editTextLayout = new LinearLayout(this);
editTextLayout.setOrientation(LinearLayout.VERTICAL);
main.addView(editTextLayout);
EditText editText1 = new EditText(this);
editText1.setId(id++);
editTextLayout.addView(editText1);
}
}
}
and the layout test.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/parent"
android:padding="10dp" >
<EditText
android:id="#+id/et_count"
android:layout_width="100dp"
android:layout_height="wrap_content" />
<Button
android:id="#+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit" />
</LinearLayout>
To add style
editTextLayout.setTextAppearance(getApplicationContext(), R.style.boldText);