Hello Friends我在listitem点击程序中使用listView执行下面的代码,但是作为Listview有很多listitem会调用不同的WEBPAGES 对于不同的网页我必须创建不同的Fragment.xml和Framgment.java文件???或者我可以保留一个公共片段和xml文件,并在列表项状态的帮助下,我可以调用不同的网页! 请在这件事上给予我帮助 作为我在android中的初学者 谢谢
fragment.xml之
<!-- TODO: Update blank fragment layout -->
<WebView
android:id="@+id/webViewabout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Fragment.java
package com.ft.bscit;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import com.ft.bscit.R;
/**
* A simple {@link Fragment} subclass.
*/
public class About_bscit_Fragment extends Fragment {
public About_bscit_Fragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_about_bscit, container, false);
WebView webView = (WebView)rootView.findViewById(R.id.webViewabout);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebChromeClient(new WebChromeClient());
webView.loadUrl("file:///android_asset/index.html");
return rootView;
}
}
答案 0 :(得分:0)
您可以在实例化片段时发送public interface CityRepository extends PagingAndSortingRepository<City, Integer>, JpaSpecificationExecutor<City> {
}
。
@Service
@Transactional
public class CityService {
@Autowired
private CityRepository cityRepository;
@Transactional(readOnly = true)
public CityListVO findByNameLike(String name, PageRequest pageRequest) {
name = "%" + name + "%";
if (pageRequest == null) {
List<City> result = cityRepository.findAll(fillGridCriteria(name));
return new CityListVO(1, result.size(), result);
} else {
Page<City> result = cityRepository. findAll(fillGridCriteria(name), pageRequest);
return new CityListVO(result.getTotalPages(), result.getTotalElements(), result.getContent());
}
}
private static Specification<City> fillGridCriteria(String name) {
return new Specification<City>() {
@Override
public Predicate toPredicate(
Root<City> root,
CriteriaQuery<?> query,
CriteriaBuilder builder) {
/*
The current return I can do a like by name, and it works fine.
My problem is if for any reason I need to do multiple joins like the folow jpql:
select ci FROM City ci, State st, Country co where ci.st = st AND st.co = co AND co.name = 'Canada';
How to do this from here ? Inside this method.
How is gonna be the return for this method ?
*/
return builder.like(root.get("name"), name.trim());
}
};
}
}
其中url
在case R.id.button1:
//what to put here
About_bscit_Fragment fragment = About_bscit_Fragment.newInstance("your-url-value");
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.fragment_container, fragment);
ft.commit();
break;
}
-
newInstance()
在Fragment的About_bscit_Fragment
中,您可以在实例化时获取您发送的值 -
public static About_bscit_Fragment newInstance(String url) {
About_bscit_Fragment fragment = new About_bscit_Fragment();
Bundle args = new Bundle();
args.putString("key_url", url);
fragment.setArguments(args);
return fragment;
}
加载它 -
onViewCreated()
答案 1 :(得分:0)
package com.forever.technology.bscit;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import com.forever.technology.bscit.R;
/**
* A simple {@link Fragment} subclass.
*/
public class Sem1Fragment_list extends ListFragment {
public Sem1Fragment_list() {
// Required empty public constructor
}
ListView lv;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_sem1_list, container, false);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
ArrayAdapter adapter = ArrayAdapter.createFromResource(getActivity(),
R.array.sem1, android.R.layout.simple_list_item_1);
setListAdapter(adapter);
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
switch (position)
{
case 0:
Intent intent = new Intent(getActivity().getApplicationContext(),Subject1Activity.class);
startActivity(intent);
case 1:
}
}
}