I have made an android app to display image from firebase into recycler view and when user click a image it has to go to its full screen page and have tried a several times but it just shows the blank activity
You can use PhotoView library (com.github.chrisbanes.photoview) to show full screen picture as below:
Piccaso is used here to show images, but you can use other image libraries such as Fresco, Glide .
ActivityLargeImageView
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.Window;
import android.widget.ProgressBar;
import android.widget.Toast;
import com.github.chrisbanes.photoview.PhotoView;
import com.github.chrisbanes.photoview.PhotoViewAttacher;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;
import java.io.File;
import butterknife.BindView;
import butterknife.ButterKnife;
public class ActivityLargeImageView extends FragmentActivity {
#BindView(R.id.photoview_image)
PhotoView photoviewImage;
#BindView(R.id.progressbar)
ProgressBar progressBar;
File mFile;
PhotoViewAttacher mAttacher;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_large_image_view);
ButterKnife.bind(this);
progressBar.setVisibility(View.VISIBLE);
String img_url = getIntent().getExtras().getString("image_url");
try {
mFile = new File(img_url);
} catch (Exception ex) {
}
if (mFile.exists()) {
Picasso.with(getApplicationContext()).load(mFile).into(photoviewImage, imageLoadedCallback);
} else {
Picasso.with(getApplicationContext()).load(img_url).into(photoviewImage, imageLoadedCallback);
}
}
Callback imageLoadedCallback = new Callback() {
#Override
public void onSuccess() {
if (mAttacher != null) {
mAttacher.update();
} else {
mAttacher = new PhotoViewAttacher(photoviewImage);
}
progressBar.setVisibility(View.GONE);
}
#Override
public void onError() {
Toast.makeText(getApplicationContext(), getResources().getString(R.string.error_message_connection_to_server), Toast.LENGTH_LONG).show();
}
};
}
XML File
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:background="#000000"
android:orientation="vertical" >
<com.github.chrisbanes.photoview.PhotoView
android:id="#+id/photoview_image"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ProgressBar
android:id="#+id/progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</FrameLayout>
Related
I am trying to build a multi page form for an application. As per suggestions here I am attempting to use a ViewModel to store the data input by the user to easily get it in another fragment, and to update the edittext to their previous input if they navigate back and forth. As well the application must have view binding.
However, when attempting to retrieve the input in a toast message in the last fragment or put it in the edittext, I get this as an output
"androidx.lifecycle.MutableLiveData#8177d2c"
Why is this happening? I am using .toString() methods with getText() so I don't know why
My code:
SharedViewModel.java
package com.loopbreakr.viewmodelform;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.MutableLiveData;
public class SharedViewModel extends ViewModel {
private MutableLiveData<CharSequence> answerOneText = new MutableLiveData<>();
private MutableLiveData<CharSequence> answerTwoText = new MutableLiveData<>();
private MutableLiveData<CharSequence> answerThreeText = new MutableLiveData<>();
public void setAnswerOneText(CharSequence input) {
answerOneText.setValue(input);
}
public void setAnswerTwoText(CharSequence input) {
answerTwoText.setValue(input);
}
public void setAnswerThreeText(CharSequence input){
answerThreeText.setValue(input);
}
public MutableLiveData<CharSequence> getAnswerOneText() {
return answerOneText;
}
public MutableLiveData<CharSequence> getAnswerTwoText() {
return answerTwoText;
}
public MutableLiveData<CharSequence> getAnswerThreeText() {
return answerThreeText;
}
}
MainActivity.java
package com.loopbreakr.viewmodelform;
import androidx.appcompat.app.AppCompatActivity;
import androidx.navigation.NavController;
import androidx.navigation.fragment.NavHostFragment;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
NavController navController = navHostFragment.getNavController();
}
}
PageOne.java fragment that I am trying to retrieve data from
package com.loopbreakr.viewmodelform;
import android.app.Activity;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import com.loopbreakr.viewmodelform.databinding.FragmentPageOneBinding;
public class PageOne extends Fragment {
private SharedViewModel sharedViewModel;
private FragmentPageOneBinding binding = null;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ViewDataBinding fragmentBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_page_one,container,false);
binding = (FragmentPageOneBinding) fragmentBinding;
return binding.getRoot();
}
#Override
public void onViewCreated(#NonNull View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
sharedViewModel = new ViewModelProvider(requireActivity()).get(SharedViewModel.class);
if(binding != null){
binding.pageOneInput.setText(sharedViewModel.getAnswerOneText().toString());
binding.nextToTwo.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
sharedViewModel.setAnswerOneText(binding.pageOneInput.getText().toString());
goNext();
}
});
binding.returnButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
goBack();
}
});
}
}
public void goNext() {
NavController navController = Navigation.findNavController(getView());
navController.navigate(R.id.action_pageOne_to_pageTwo);
}
public void goBack(){
NavController navController = Navigation.findNavController(getView());
navController.navigate((R.id.action_pageOne_to_description));
}
}
Last fragment PageThree.java where I attempt to get the data and display it as a toast message
package com.loopbreakr.viewmodelform;
import android.app.Activity;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import com.loopbreakr.viewmodelform.databinding.FragmentPageOneBinding;
public class PageOne extends Fragment {
private SharedViewModel sharedViewModel;
private FragmentPageOneBinding binding = null;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ViewDataBinding fragmentBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_page_one,container,false);
binding = (FragmentPageOneBinding) fragmentBinding;
return binding.getRoot();
}
#Override
public void onViewCreated(#NonNull View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
sharedViewModel = new ViewModelProvider(requireActivity()).get(SharedViewModel.class);
if(binding != null){
binding.pageOneInput.setText(sharedViewModel.getAnswerOneText().toString());
binding.nextToTwo.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
sharedViewModel.setAnswerOneText(binding.pageOneInput.getText().toString());
goNext();
}
});
binding.returnButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
goBack();
}
});
}
}
public void goNext() {
NavController navController = Navigation.findNavController(getView());
navController.navigate(R.id.action_pageOne_to_pageTwo);
}
public void goBack(){
NavController navController = Navigation.findNavController(getView());
navController.navigate((R.id.action_pageOne_to_description));
}
}
Also, here are the XMLs incase they are relevant
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.fragment.app.FragmentContainerView
android:id="#+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="#navigation/nav_graph" />
</androidx.constraintlayout.widget.ConstraintLayout>
fragment_page_one.xml
<?xml version="1.0" encoding="utf-8"?>
<layout>
<data>
<variable
name="viewModel"
type="com.loopbreakr.viewmodelform.SharedViewModel"/>
</data>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".PageOne">
<!-- TODO: Update blank fragment layout -->
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/hello_blank_fragment" />
<Button
android:id="#+id/nextToTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="next"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<Button
android:id="#+id/returnButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Return"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<MultiAutoCompleteTextView
android:id="#+id/pageOneInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textAutoCorrect|textMultiLine"
android:maxLines="4"
android:minLines="4"
app:layout_constraintBottom_toBottomOf="#+id/textView2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
override the toString method in model class it will work
#Override
public String toString() {
return "BeanDetails{" +
"sl_no='" + sl_no + '\'' +
", type='" + type + '\'' +
", count='" + count + '\'' +
", percent='" + percent + '\'' +
'}';
}
in my model class there is four variable so that is why it is showing 4 variable inside the beandetails
I am using google image search to look for images and get the URL of the first image in my android application using JSOUP library
My problem is that no matter how much I try It shows me that the URL is null
looks like the element that contains the first image does not have a url
here is the XML file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="arb.myapplication.MainActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="#mipmap/ic_launcher"
android:layout_alignParentBottom="true"
android:layout_marginBottom="131dp"
android:id="#+id/imageView" />
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="39dp"
android:layout_marginEnd="39dp"
android:layout_marginTop="11dp"
android:id="#+id/button3"
android:elevation="0dp" />
Ignore the image view
I use the button to get the url of the image
here is the JAVA file
package arb.myapplication;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Toast;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Attribute;
import org.jsoup.nodes.Attributes;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
public class MainActivity extends AppCompatActivity {
class DownloadIcon extends AsyncTask<Object, Object, Integer>
{
#Override
protected Integer doInBackground(Object... objects) {
Connection connecion= Jsoup.connect("http://www.google.com/search?tbm=isch&q=facebook+logo");
try {
Document document=connecion.get();
Elements element=document.select("img.rg_ic.rg_i");
String url=element.first().absUrl("src");
publishProgress(url);
} catch (IOException e1) {
publishProgress(-1);
}
return 0;
}
#Override
protected void onProgressUpdate(Object... values) {
/* ImageView imageView=(ImageView) findViewById(R.id.imageView);
try {
InputStream inputStream= new URL(values[0].toString()).openStream();
imageView.setImageBitmap(BitmapFactory.decodeStream(inputStream));
} catch (IOException e) {
throw new RuntimeException(e);
}*/
Toast.makeText(getBaseContext(),values[0].toString(),Toast.LENGTH_LONG).show();
}
#Override
protected void onPostExecute(Integer integer) {
Toast.makeText(getBaseContext(),"done",Toast.LENGTH_SHORT).show();
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button3=(Button) findViewById(R.id.button3);
button3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
new DownloadIcon().execute();
}
});
}
}
in the onProgressUpdate function does not show the Toast because its text is null
I already tried to get the attribute keys and values of the chosen element
It matches those displayed when I parse the element using the Chrome explorer but without src attribute
The text is null because you get no images. If you debug your request you'll see 403 status code which tells you that Jsoup client is not authorized to fetch images from Google. You need to use or emulate browser to achieve your goal.
i have tried the all the suggestions for this. All that answers are changing the fragment from a activity but here is the difference in my question. i am trying to change one fragment to another fragment from the first fragment.Please help me .
i have a fragment which contains dynamic buttons.please find the image [![enter image description here][1]][1]
If the user clicks any of the button i want to show some stack cars for the same.see the image [![enter image description here][2]][2]
Ok this is my requirement. My problem is i have one activity which contains the bottom navigation bar names as ShowDashBoardActivity
ShowDashBoardActivity.java
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.Toast;
import com.yourname.R;
import com.yourname.fragments.DashBoardJobList;
import com.yourname.fragments.DashBoardOne;
import com.yourname.fragments.DashBoardTaskBubble;
import com.roughike.bottombar.BottomBar;
import com.roughike.bottombar.BottomBarBadge;
import com.roughike.bottombar.BottomBarFragment;
import butterknife.Bind;
public class ShowDashBoardActivity extends AppCompatActivity {
private BottomBar bottomBar;
LinearLayout CardAspirationLayout,TextCardAspirationLayout;
DashBoardOne _DashBoardOne;
Context context;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.show_dash_board_activity);
context=getApplicationContext();
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setDisplayShowCustomEnabled(true);
getSupportActionBar().setCustomView(R.layout.custom_action_bar_layout);
View view =getSupportActionBar().getCustomView();
/*ImageButton imageButton= (ImageButton)view.findViewById(R.id.action_bar_back);
imageButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
});*/
bottomBar = BottomBar.attach(this, savedInstanceState);
bottomBar.setFragmentItems(getSupportFragmentManager(), R.id.fragmentContainer,
new BottomBarFragment(DashBoardOne.newInstance("Content for Dashboard."), R.drawable.dashboard, "Dashboard"),
new BottomBarFragment(DashBoardTaskBubble.newInstance("Content for Task."), R.drawable.task, "Task"),
new BottomBarFragment(DashBoardJobList.newInstance("Content for Job."), R.drawable.job, "Job")
);
TextCardAspirationLayout=(LinearLayout) findViewById(R.id.TextCardAspirationLayout);
bottomBar.setActiveTabColor("#C2185B");
BottomBarBadge unreadMessages = bottomBar.makeBadgeForTabAt(2, "#E91E63", 4);
unreadMessages.show();
unreadMessages.setAnimationDuration(200);
unreadMessages.setAutoShowAfterUnSelection(true);
// bottomBar.useDarkTheme(true);
}
}
show_dash_board_activity.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/slidetwo"
xmlns:tools="http://schemas.android.com/tools" >
</FrameLayout>
The navigation drawer is working perfect. the in the DashBoardTaskBubble.java it is fragment i am drawing dynamic bubble to show like picture 1.
DashBoardTaskBubble.java
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewCompat;
import android.support.v7.widget.AppCompatButton;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.panenviron.R;
import java.util.ArrayList;
import java.util.List;
import static android.R.attr.tint;
public class DashBoardTaskBubble extends Fragment {
private static final String STARTING_TEXT = "Four Buttons Bottom Navigation";
public DashBoardTaskBubble() {
}
public static DashBoardTaskBubble newInstance(String text) {
Bundle args = new Bundle();
args.putString(STARTING_TEXT, text);
DashBoardTaskBubble dashBoardTaskBubble = new DashBoardTaskBubble();
dashBoardTaskBubble.setArguments(args);
return dashBoardTaskBubble;
}
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_task_bubble, container, false);
final RelativeLayout workViewLayout = (RelativeLayout)view.findViewById(R.id.workView);
int iNumberOfButtons = 6; // no of bubble create function to fetch no of bubble from db
// create a function to get color from db now give static
String[] colourList = new String[] { "#ffaa00","#32CD32","#0000FF"};
Button[] dynamicButtons = new Button[iNumberOfButtons];
List<String> tempColouersList= new ArrayList<String>();
for (int i = 0; i < iNumberOfButtons; i++) {
dynamicButtons[i] = new Button(getActivity());
dynamicButtons[i].setText("+"+i+5);
dynamicButtons[i].setId(i);
dynamicButtons[i].setTextSize(15.0f);
dynamicButtons[i].setBackgroundResource(R.drawable.round_button);
if(i==0){
RelativeLayout.LayoutParams paramsButton =
new RelativeLayout.LayoutParams(350,350);
paramsButton.setMargins(50,0,0,0);
dynamicButtons[0].setLayoutParams(paramsButton);
tempColouersList.add(colourList[0]);
} else if(i==1){
RelativeLayout.LayoutParams paramsButton2 =
new RelativeLayout.LayoutParams(350,350);
paramsButton2.setMargins(700,10,0,0);
dynamicButtons[1].setLayoutParams(paramsButton2);
tempColouersList.add(colourList[1]);
} else if(i==2){
RelativeLayout.LayoutParams paramsButton3 =
new RelativeLayout.LayoutParams(350,350);
paramsButton3.setMargins(400,250,0,0);
dynamicButtons[2].setLayoutParams(paramsButton3);
tempColouersList.add(colourList[2]);
} else if(i==3){
RelativeLayout.LayoutParams paramsButton4 =
new RelativeLayout.LayoutParams(350,350);
paramsButton4.setMargins(50,450,0,0);
dynamicButtons[3].setLayoutParams(paramsButton4);
tempColouersList.add(colourList[1]);
} else if(i==4){
RelativeLayout.LayoutParams paramsButton5 =
new RelativeLayout.LayoutParams(350,350);
paramsButton5.setMargins(700,500,0,0);
dynamicButtons[4].setLayoutParams(paramsButton5);
tempColouersList.add(colourList[2]);
}else if(i==5){
RelativeLayout.LayoutParams paramsButton6 =
new RelativeLayout.LayoutParams(350,350);
paramsButton6.setMargins(350,700,0,0);
dynamicButtons[5].setLayoutParams(paramsButton6);
tempColouersList.add(colourList[0]);
}
ColorStateList tint = new ColorStateList(new int[][]{new int[0]}, new int[]{Color.parseColor(tempColouersList.get(i)) });
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP && dynamicButtons[i] instanceof AppCompatButton) {
((AppCompatButton) dynamicButtons[i]).setSupportBackgroundTintList(tint);
} else {
ViewCompat.setBackgroundTintList(dynamicButtons[i], tint);
}
dynamicButtons[i].setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
try {
Log.e("im on","button clik");
} catch (Exception e) {
e.printStackTrace();
}
}
});
workViewLayout.addView(dynamicButtons[i]); // dynamicButtonsLinearLayout is the container of the buttons
}
return view;
}
public void replaceFragments( ) {
Log.e("im on","replaceFragments");
//Fragment fragment = null;
try {
//fragment = (Fragment) TaskCardListShow.newInstance();
/*TaskCardListShow nextFrag= new TaskCardListShow();
this.getFragmentManager().beginTransaction()
.replace(R.id.fragmentContainer, nextFrag)
.addToBackStack(null)
.commit();*/
FragmentManager mFragmentManager = getFragmentManager();
FragmentTransaction mFragmentTransaction = https://i.stack.imgur.com/J75iJ.pngmFragmentManager.beginTransaction();
TaskCardListShow mFragment = new TaskCardListShow();
//mFragmentTransaction.replace(R.id.fragmentContainer, mFragment);
mFragmentTransaction.add(R.id.fragmentContainer, mFragment);
mFragmentTransaction.addToBackStack(null);
mFragmentTransaction.commit();
} catch (Exception e)
{ e.printStackTrace(); }
// Insert the fragment by replacing any existing fragment FragmentManager
// fragmentManager = getSupportFragmentManager();
// fragmentManager.beginTransaction().replace(R.id.flContent, fragment).commit();
}
}
fragment_task_bubble.xml
<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:gravity="center_horizontal"
android:orientation="vertical"
android:background="#drawable/slidetwo">
<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="0dp"
android:layout_weight="12"
android:background="#color/white">
</LinearLayout>
<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="0dp"
android:layout_weight="88"
android:orientation="vertical"
android:background="#color/white">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="3dp"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="5dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="20dp">
<View
android:layout_width="98dp"
android:gravity="center_horizontal"
android:layout_height="4dp"
android:background="#android:color/holo_red_dark"
android:id="#+id/normalViewSeparator"
/>
</LinearLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="30"
android:orientation="vertical"
android:id="#+id/workView"
android:background="#color/white">
</RelativeLayout>
</LinearLayout>
</LinearLayout>
The bubble drawing is also working perfect. Here i trying to add some features like if a user clicks a button i want to show the stack cards like picture 2
I am thinking to display the task cards in fragment . I dont know how to navigate one fragment to another fragment.
TaskCardListShow.java FRAGMENT
package com.panenviron.fragments;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.panenviron.R;
public class TaskCardListShow extends Fragment {
public TaskCardListShow() {
}
public static TaskCardListShow newInstance() {
TaskCardListShow _TaskCardListShow = new TaskCardListShow();
return _TaskCardListShow;
}
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.task_card_list_show, container, false);
Log.e("im on","TaskCardListShow");
return view;
}
}
task_card_list_show.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/fragment_task_card_list_show"
style="#style/Animation.AppCompat.Dialog">
<TextView
android:text="Im on task fragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView"
android:layout_weight="1" />
</LinearLayout>
i tried the above replaceFragments( ) custom function. But it is replaces the fragment but it is not removing the first fragment. How can do this.
Your are using support fragments (android.support.v4.app.Fragment) with native fragmentmanager - Activity.getFragmentManager(). Instead you have to use support fragmentmanager - AppCompatActivity.getSupportFragmentManager().
I really wish android tools would handle this annoying situation better.
inside the fragment you have to call getActivity().getSupportFragmentManager() instead of getFragmentManager. so you have to give like this "getActivity().getSupportFragmentManager().beginTransaction()" in the fragment transaction. after that you can replace simply like already done
I am making this question today because I can not find certain information on google and/or Stack Overflow. My Problem is, I am creating a Android Application and I want certain information from a Website. So I use Jsoup as my parse Library. I follow all the instruction and set The data in the Text to Show up with The HTML text. For Some reason it is either a network connection or my code is wrong in communicating with the website? I do not know what is up with the app. I am Using Android Studio, so when running either the emulator or on a device it will just not pull html from the website.
Here is My code for 2 Classes. This has to be in Java.
package update.app.jdog1218.com.messingaround;
import android.app.Activity;
import android.app.DialogFragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import java.net.URL;
import java.net.URLConnection;
public class MainActivity extends Activity {
private Button answer_Button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RelativeLayout bible = new RelativeLayout(this);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
return super.onOptionsItemSelected(item);
}
public void gotoInbeddedBible(MenuItem item) {
Intent bibleclass = new Intent(this, bible.class);
final int result = 1;
bibleclass.putExtra("callingActivity", "MainActivity");
startActivity(bibleclass);
startActivityForResult(bibleclass, result);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}
public void exit(MenuItem item) {
Button exitProcess = (Button) findViewById(R.id.submit);
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(1);
}
public void sotd(MenuItem item) {
Intent clickedSotd = new Intent(this, Sotd.class);
int result = 1;
startActivity(clickedSotd);
}
}
This is the class I want to use Jsoup in.
package update.app.jdog1218.com.messingaround;
import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.view.Menu;
import android.widget.TextView;
import org.jsoup.Jsoup;
import org.jsoup.Connection;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.w3c.dom.Node;
import org.w3c.dom.Text;
import java.io.IOException;
import static org.jsoup.Jsoup.*;
/*
* Created by Joel on 5/28/2015.
*/
public class Sotd extends Activity {
#Override
protected void onStart() {
super.onStart();
}
String title;
#Override
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
setContentView(R.layout.sotd);
Intent activityThatCalled = getIntent();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
return super.onCreateOptionsMenu(menu);
}
/**
* Pull and Parse the HTML of Compass HB for SOTD.
*
* #return DocumentString
* #throws IOException
*/
protected String pullHTML() {
super.onStart();
final String url = "https://www.compasshb.com/api/v1/passages";
Document doc = null;
TextView textView = (TextView) findViewById(R.id.SOTD);
try {
doc = Jsoup.connect(url).get();
textView.setText(doc.ownText());
String paragraph = doc.title();
return paragraph;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
#Override
protected void onPostResume() {
super.onPostResume();
}
}
This is the XML File for the Layout I want to output too.
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:weightSum="1"
android:background="#drawable/the_rendered_background">
<TextView
android:text="#string/text_of_activity_main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:height="40dp"
android:capitalize="none"
android:width="200dp"
android:textColor="#000000"
android:id="#+id/text_view" />
</LinearLayout>
SOTD is where I want it to output too.
<?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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".Sotd"
android:weightSum="1"
android:background="#drawable/the_rendered_background"
android:backgroundTintMode="add">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/SOTD"
/>
</LinearLayout>
Pretty Much I just need someone to tell me what I am doing wrong./Review
I want to display my blog as a part of an android application..i have the code ready..it works well when displaying websites like google etc but not with my blog..can someone help me solve this problem
mainActivity.java:
package com.mkyong.android;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
private Button button;
public void onCreate(Bundle savedInstanceState) {
final Context context = this;
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button = (Button) findViewById(R.id.buttonUrl);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(context, WebViewActivity.class);
startActivity(intent);
}
});
}
}
webViewActivity.java:
package com.mkyong.android;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class WebViewActivity extends Activity {
private WebView webView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("pavan7vasan.blogspot.com");
}
}
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" >
<Button
android:id="#+id/buttonUrl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Go to http://www.google.com" />
</LinearLayout>
webview.xml:
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
it shows web page not available in the android emulator
Change this line, and it should work.
webView.loadUrl("http://pavan7vasan.blogspot.com");